Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I check an http request response status code from iOS?

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.

like image 232
Joey Avatar asked Feb 08 '11 20:02

Joey


People also ask

How do I get HTTP response status code?

Use HttpResponse. getStatusLine() , which returns a StatusLine object containing the status code, protocol version and "reason".

How do you validate a response status code?

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 do I get swift status 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?


1 Answers

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 :)

like image 158
Augustine P A Avatar answered Oct 26 '22 19:10

Augustine P A