Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa touch 异步请求iOS 6的NSURLConnection状态代码_Cocoa Touch_Ios6_Http Status Code 401_Nsurlconnectiondelegate_Sendasynchronousrequest - Fatal编程技术网

Cocoa touch 异步请求iOS 6的NSURLConnection状态代码

Cocoa touch 异步请求iOS 6的NSURLConnection状态代码,cocoa-touch,ios6,http-status-code-401,nsurlconnectiondelegate,sendasynchronousrequest,Cocoa Touch,Ios6,Http Status Code 401,Nsurlconnectiondelegate,Sendasynchronousrequest,当前正在使用sendAsynchronous from NSURLConnection发出post和get请求,但无法在响应中获取状态代码。大多数帖子建议使用NSURLConnection及其委托方法,据我所知,它们也是异步的 我不明白委托如何将信息发送回调用方法(最终需要数据的方法)。sendAsynchronous方法具有我正在使用的回调 我是新手,谢谢你的帮助 当您使用sendAsynchronousRequest:queue:completionHandle方法时,我将尝试在该上下文中回

当前正在使用sendAsynchronous from NSURLConnection发出post和get请求,但无法在响应中获取状态代码。大多数帖子建议使用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);
}];

当您使用
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);
}];

我有一个包装器类,它使这变得非常简单,并保持代码干净:

我有一个包装器类,它使这项工作变得非常简单,并保持代码整洁: