当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - Handle NSURLRequest Response

问题描述:

I am working on an app that queries a web service. I want to know how can I handle errors like "404" (NOT FOUND). The delegate method connection:(NSURLConnection *)conn didFailWithError:(NSError *)error only handles errors caused by connection. I have been told that dealing with those errors should be in connection:(NSURLConnection *)conn didReceiveData:(NSData *)data method, how can I do that? I've been looking over the documentation, there is no such property of NSURLRequest like "ResponseCode" or something. Any help is appreciated.

网友答案:

Implement the following delegate method

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse
 *)response

Then check the response object for a statusCode property. You may have to cast it to NSHTTPURLResponse to see it.

分享给朋友:
您可能感兴趣的文章:
随机阅读: