Meh*_*zai 1 cocoa-touch http-status-code-401 nsurlconnectiondelegate sendasynchronousrequest ios6
目前使用来自NSURLConnection的sendAsynchronous来发布和获取请求,但无法获取响应中的状态代码.大多数帖子都建议使用NSURLConnection及其委托方法,我理解它们也是异步的.
我不明白委托如何将信息发送回调用方法(最终需要数据的方法).sendAsynchronous方法有一个我现在正在使用的回调.
我是新来的,谢谢你的帮助.
当您使用sendAsynchronousRequest:queue:completionHandle方法时,我将尝试在该上下文中回答:
[NSURLConnection sendAsynchronousRequest:request
queue:queue
completionHandler:
^(NSURLResponse *response, NSData *data, NSError *error) {
// This will get the NSURLResponse into NSHTTPURLResponse format
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
// This will Fetch the status code from NSHTTPURLResponse object
int responseStatusCode = [httpResponse statusCode];
//Just to make sure, it works or not
NSLog(@"Status Code :: %d", responseStatusCode);
}];
Run Code Online (Sandbox Code Playgroud)