NSUrlConnectionDelegate - 获取http状态代码 [英] NSUrlConnectionDelegate - Getting http status codes

查看:186
本文介绍了NSUrlConnectionDelegate - 获取http状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS中,如何从Web服务器接收响应的http状态代码(404,500 200等)。我假设它在NSUrlConnectionDelegate中。

in iOS, how can I receive the http status code (404,500 200 etc) for a response from a web server. I am assuming it's in the NSUrlConnectionDelegate.

Objective-C或 Monotouch .NET回答确定。

Objective-C or Monotouch .NET answer ok.

推荐答案

是的,您可以在委托方法-didRecieveResponse中获取状态代码:

Yes, you can get status code in delegate method -didRecieveResponse:

- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
   NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
   int code = [httpResponse statusCode];
}

这篇关于NSUrlConnectionDelegate - 获取http状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆