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

查看:26
本文介绍了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天全站免登陆