사용자가 유효한지 보려면 REST API를 누르려고합니다. connectionDidFinishLoading
실행을 알고 있지만 응답 (XML)을 확인하는 방법을 모르겠습니다. 제발 조언.xml post loading xml 응답
signIn
기능은 일반적으로 당신이 NSXMLParser
을 사용 XML
을 구문 분석
- (IBAction)signIn:(id)sender;
{
[emailError setHidden:YES];
if([emailAddressTxt text] && [passwordTxt text]) {
// send user/pass to server for validation
if([self NSStringIsValidEmail:[emailAddressTxt text]]) {
NSString *post = [NSString stringWithFormat:@"Email=%@&Password=%@", emailAddressTxt.text, passwordTxt.text];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://www.mySite.com/validate.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
[NSURLConnection connectionWithRequest:request delegate:self];
}
} else {
// give error dialogue
[emailError setText:@"User not found"];
[emailError setHidden:NO];
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
//[signInData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d {
//[signInData appendData:d];
// updated to:
signInData = (NSMutableData *)d;
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
// Fail..
[emailError setText:@"Connection Error"];
[emailError setHidden:NO];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseText = [[NSString alloc] initWithData:signInData encoding:NSUTF8StringEncoding];
NSLog(@"%@", @"check");
NSLog(@"%@", responseText);
}
// an example response would be:
// <string xmlns="http://thedomain.com/">invalid login</string>
xml 응답을 구문 분석하는 방법을 묻는 질문이 있으십니까? – cpjolicoeur