Note that there are some explanatory texts on larger screens.

plurals
  1. POxml post loading xml response
    text
    copied!<p>I'm trying to hit a REST api to see if a user is valid. I know the <code>connectionDidFinishLoading</code> runs, but I'm not sure how to check the response (xml). Please advise.</p> <p>The <code>signIn</code> function gets the ball rolling</p> <pre><code>- (IBAction)signIn:(id)sender; { [emailError setHidden:YES]; if([emailAddressTxt text] &amp;&amp; [passwordTxt text]) { // send user/pass to server for validation if([self NSStringIsValidEmail:[emailAddressTxt text]]) { NSString *post = [NSString stringWithFormat:@"Email=%@&amp;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: // &lt;string xmlns="http://thedomain.com/"&gt;invalid login&lt;/string&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload