1
votes

I am using ASIHttpRequest Library to make parallel asynchronous web calls. Here is the code snippet of the actual method.

- (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];
}

When I 'NSLog' the request.responseString property of the request, I am getting nothing displayed in the console. I used Wireshark to check if the link is sending any response or not and seems like it is sending proper response.

when I 'NSLog' responseHeaders it shows proper values. Here is code snippet for that:

-(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]];
}

Also I am getting response data in this method(But not in RequestFinished: method):

-(void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data
{
NSLog(@"%@",data);
NSLog(@"%@", [[request responseHeaders] objectForKey:@"Content-Type"]);
}

Please help me get proper response...!!!

Thanks in advance.

1
So you are getting HTTP-headers but no content? Does request.responseData show anything when logged?Till
I am not getting anything in request.responseData as well.Rishabh Tayal
What response code are you getting?atxe

1 Answers

1
votes

I figured it out. Instead of setting delegate for ASIHttpRequest, I needed to set delegate for _queue.

Using

[_queue setDelegate:self] worked out for me...