Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

HTTPClient returning a false timeout on 3G only.

Hi. I've got an app running on an iPhone. Works fine in the simulator. Upload it to my phone (3GS with 4.0.2) and after a post to an HTTP Client I get the following error:

error = "Error Domain=ASIHTTPRequestErrorDomain Code=2\"The request timed out\" UserInfo=0x37d2e0 {NSLocalizedDescription=The request timed out}"; source=[object TiNetworkClient];

NOTE: This only happens when my post includes an image taken with the camera. No image or an image from the Gallery is fine. image from the camera is fine in wi-fi mode.

Even more perplexing the photo is actually uploaded to the server correctly, so it appears this is a "false" timeout?

I have tried resizing the images (down to < 100kb), and I still get the error.

Any suggestions?

— asked August 29th 2010 by Jennifer Bonnett
  • 3g
  • httpclient
  • iphone
  • timeout
1 Comment
  • I'm having the same issue, ever find a fix?

    — commented April 5th 2011 by Rob Marston

3 Answers

  • I found an undocumented setting, "enableKeepAlive" for createHTTPClient. Doing the following fixes the issue:

    xhr = Titanium.Network.createHTTPClient({
    
        enableKeepAlive:false
    });
    

    The problem is with the server not sending a "100-Continue" header, which the ASIHTTPRequest used in Titanium is waiting for.

    in native the solution will be:
    ASIHTTPRequest *req = [ASIHTTPRequest requestWithURL:url];
    req.shouldAttemptPersistentConnection = NO;

    But for titanium, the above statement works!

    Harald Sakshaug

    — answered August 18th 2011 by Harald Sakshaug
    permalink
    3 Comments
    • I can confirm that this fixes the issue. I was having problems with a JSON request from twitter returning no data on 3G, however it was working fine on WiFi.

      After adding enableKeepAlive:false fixed the issue.

      Thanks Harald.

      — commented November 15th 2011 by Adam Moritz
    • I tried this setting in the past with no effect. I will give it another shot when I find some spare time on 1.7.5.

      — commented November 16th 2011 by Jonathon Kresner
    • This fixed the issue (I was seeing the error for slow 3g networks), thanks Harald!

      — commented January 18th 2012 by Chris K
  • This is a common problem. ImageView also times out after a very short time. And there is no way to set the timeout longer.

    — answered April 17th 2011 by Ronald van Woensel
    permalink
    0 Comments
  • Help! I am also having this issue. Tried so many things. Any solution?

    — answered August 17th 2011 by Jonathon Kresner
    permalink
    3 Comments
    • Same issue this end, I will keep you posted if I find a solution.

      — commented August 18th 2011 by Harald Sakshaug
    • Solution posted below Jonathon!

      — commented August 18th 2011 by Harald Sakshaug
    • Hey guys. I am having the same issue. Tried enableKeepAlive for no use. SetTimeout doesn't work either. Help!

      — commented May 10th 2013 by Shahzad Atta
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.