我正在使用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"]);
}
请帮助我得到适当的回应...... !!!
提前致谢。
答案 0 :(得分:1)
我明白了。我没有为ASIHttpRequest设置委托,而是需要为_queue设置委托。
使用
[_queue setDelegate:self] worked out for me...