接收401时ASIHttpRequest响应数据/标头空

时间:2011-05-30 22:16:38

标签: iphone asihttprequest http-status-code-401

每当服务器返回401时,ASIHTTPRequest的响应数据和头字段始终为null。

我只能读取设置为ASIAuthenticationErrorType的状态代码和NSError代码。我正在使用Charles Web Proxy嗅探流量。我可以清楚地看到服务器正在返回一个非空响应体。

我已经尝试实现authenticationNeededForRequest:delegate以查看响应数据是否为null。但是,这个委托方法永远不会被调用。

这是我用来初始化网络队列的代码:

networkQueue = [[ASINetworkQueue alloc] init];
[networkQueue setDelegate:self];
[networkQueue setRequestDidFinishSelector:@selector(requestDidFinish:)];
[networkQueue setRequestDidFailSelector:@selector(requestDidFail:)];

并发送请求

ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:apiURL];
request.delegate = self;
request.userInfo  = userInfo;
[request setRequestMethod:method];
[networkQueue addOperation:request];
[networkQueue go];

谢谢!

2 个答案:

答案 0 :(得分:1)

显然,这是以前版本的ASIHttpRequest中的一个错误。它应该在当前版本上修复。

答案 1 :(得分:0)

如果您已实现委托方法 - (void)请求:(ASIHTTPRequest *)请求didReceiveData:(NSData *)数据

然后,responseData将为null。因为API会将数据处理移交给应用程序。

相关问题