앱을 만들고 있습니다. 나는 HTTP POST 메쏘드를 사용하여 로그인 정보를 보내고있다. 서버로부터받는 replyI'm은 HTML 형식이다. 해당 HTML을 구문 분석하고 연속 또는 실패에 대해 다른 메소드를 추가하려면 어떻게해야합니까? 내가 달성하고자하는 것은 로그인 실패시 UIAlerView를 사용하여 메시지를 표시하고 로그인에 성공하면 앱이 애니메이션으로보기를 변경해야한다는 것입니다. :)HTML 응답 구문 분석 - iPhone App
내가 지금 사용하고 코드 : I는 내가 HTMLparser 클래스를 사용 정확히 했는가
- (IBAction) loginButton: (id) sender {
indicator.hidden = NO;
[indicator startAnimating];
loginbutton.enabled = NO;
// Create the username and password string.
// username and password are the username and password to login with
NSString *postString = [[NSString alloc] initWithFormat:@"username=%@&password=%@",userName, password];
// Package the string in an NSData object
NSData *requestData = [postString dataUsingEncoding:NSASCIIStringEncoding];
// Create the URL request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:@"http://localhost/dologin.php"]]; // create the URL request
[request setHTTPMethod: @"POST"]; // you're sending POST data
[request setHTTPBody: requestData]; // apply the post data to be sent
// Call the URL
NSURLResponse *response; // holds the response from the server
NSError *error; // holds any errors
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&error]; // call the URL
/* If the response from the server is a web page, dataReturned will hold the string of the HTML returned. */
NSString *dataReturned = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
alertWithOkButton = [[UIAlertView alloc] initWithTitle:@"Status..." message:[NSString stringWithFormat:@"%@",dataReturned] delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alertWithOkButton show];
[alertWithOkButton release];
}
넓은 질문입니다. 우선 HTML 구문 분석은 아마 여기에있는 방법이 아닙니다. SOAP 형식의 것이 바람직 할 수 있습니다. HTML의 모호한 부분에서 로그인을 분리하는 것이 좋을 것이므로, 할 수 있다면 그렇게하는 것이 좋습니다. 둘째, 노출 된 암호를 게시하는 것은 HTTPS를 사용하지 않는 한 나쁜 생각입니다. 셋째,이 질문을보십시오 : http://stackoverflow.com/questions/405749/parsing-html-on-the-iphone – Robert
로버트에게 고마워, 내가 이것을 선택할 수 있도록 대답으로 올리면 어떨까. :) –