I am sending an http request from iOS (iPad/iPhone) to my python google app engine server using the NSURLConnection
and NSURLRequest
classes.
How do I read the response's status, i.e. the value set by app engine using response.set_status(200, message="Success")
for instance?
I'm not able to find where I can read these status codes once I receive the NSURLConnection's
connectionDidFinishLoading
delegate call on the client end.
Use HttpResponse. getStatusLine() , which returns a StatusLine object containing the status code, protocol version and "reason".
We can read the status code using the getStatusCode() method. Similarly, we can read the status line using the getStatusLine () method of the response interface. Once the status is read, then we can verify if the code is a success (200) or any other code.
How To check response. statusCode in SendSynchronousRequest in Swift The Code is Below : let urlPath: String = "URL_IS_HERE" var url: NSURL = NSURL(string: urlPath) var request: NSURLRequest = NSURLRequest(URL: url) var response: AutoreleasingUnsafeMutablePointer<NSURLResponse?> = nil var error: NSErrorPointer?
If you are sending a synchronous request, you could get the response code from NSHTTPURLResponse.
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URL_LOGIN]];
NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"~~~~~ Status code: %d", [response statusCode]);
Hope this will help you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With