我正在使用 ASIHttpRequest 库进行并行异步 Web 调用。这是实际方法的代码片段。
- (void)dataForURI:(NSString *)dataURI andTag:(NSString*)tag
{
NSLog(@"%d",_queue.requestsCount);
if (!_queue) {
_queue = [ASINetworkQueue queue];
}
ASIHTTPRequest* request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:dataURI]];
[request setTimeOutSeconds:30];
[request setDownloadProgressDelegate:self];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestFinished:)];
[request setDidFailSelector:@selector(requestFailed:)];
[request setDidReceiveResponseHeadersSelector:@selector(requsestResponseHeaderReceived:)];
[request setShouldContinueWhenAppEntersBackground:YES];
[request setTag:[tag integerValue]];
[_queue addOperation:request];
[_queue go];
}
当我“NSLog”请求的 request.responseString 属性时,控制台中没有显示任何内容。我使用 Wireshark 检查链接是否正在发送任何响应,并且看起来它正在发送正确的响应。
当我'NSLog' responseHeaders 它显示正确的值。这是代码片段:
-(void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"%@",request.responseString);
NSLog(@"%@",[[request responseHeaders] objectForKey:@"Content-Type"]);
[self imageHandlerDidDownloadData:request.responseData mimeType:[request.responseHeaders objectForKey:@"Content-Type"] forMediaID:[NSString stringWithFormat:@"%d", request.tag]];
}
我也在这个方法中得到响应数据(但不是在 RequestFinished: 方法中):
-(void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data
{
NSLog(@"%@",data);
NSLog(@"%@", [[request responseHeaders] objectForKey:@"Content-Type"]);
}
请帮助我得到正确的回应......!!!
提前致谢。