私はユーザーが有効かどうかを確認するために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