4

I use ASIHTTPRequest framework in my iPhone application to manage the HTTP communication. I followed their examples given in the project home page to send asynchronous requests. There we have to implement two callbacks, one for requestFinish and other for requestFailed.

However, 60% of the time requests sent by the iPhone ends up in the "requestFinish" callback method and gives a valid HTTP status code. But sometimes it goes to "requestFailed" callback and the status code become '0' which is confusing. My investigations revealed that the internet connection is ok, and I am sending the request to the correct URL, however no log messages found in server log. So why does the request gets dropped in the middle so randomly? Has anyone came across with this type of issue. Will be very helpful.

Thanks

chathuram
  • 616
  • 2
  • 5
  • 23

3 Answers3

5

Are you looking at the status code of the ASIHTTPRequest object? That code is simply an HTTP response code - if you didn't get a response, then that should be zero.

Instead, you want to look at the NSError object that the delegate failure callback gives you.

I would use something like:

NSLog(@"%@",[error localizedErrorDescription]);

To print out to the log what the error is. Of course, "error" is the name of the variable in the method signature - you should double-check that, I think that's what the default is.

makdad
  • 6,402
  • 3
  • 31
  • 56
1

In [ASHTTPRequest initialize], I changed

[sharedQueue setMaxConcurrentOperationCount:4]

to

[sharedQueue setMaxConcurrentOperationCount:10]

This work for me, but I don't know why.

MORE:

I found this.

Community
  • 1
  • 1
Feng Stone
  • 77
  • 1
  • 3
0

As well as what phooze suggested, there is logging in ASIHTTPRequestConfig.h that you can enable, that may provide a clue as to what is happening.

JosephH
  • 37,173
  • 19
  • 130
  • 154
  • Thanks for all the replies. Yes I logged the ASIHTTPRequest calls using NSError coming from that, and also I monitored the calls reaching the Server end from TCP packet level.So the strangest issue I can see is that the request packets are reaching the server, and server sends 200 status code with message body however the request failed is invoked from iPhone and the status code is zero. So we clearly see that the server sends 200 but how come it becomes 0 at iPhone end – chathuram Nov 24 '10 at 15:16
  • By the way I logged the Error message from ASIHTTPRequest, so it complains about a timeout, however the roundup time is very short and the network speed is high. So it's pretty weired. – chathuram Nov 24 '10 at 15:25
  • 1
    Well, you could try increasing the timeout ([request setTimeout:200] if I recall correctly) and see if that helps. The debugging information I mentioned may show something more, you could edit the debug output into your question once you've collected it. – JosephH Nov 24 '10 at 16:51