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

萝らか妹 提交于 2019-11-29 04:09:38

The connection:didReceiveResponse: delegate method is called when a response is received, which gives you an NSURLResponse to play with.

If you've made an HTTP request, then it'll actually be an NSHTTPURLResponse object, which has a statusCode method.

Augustine P A

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!