HTTClient.responseText empty

You must Login before you can answer or comment on any questions.

Hi, I'm having a hard time while parsing a remote JSON file which I obtain using HTTPClient. The "onload" event fires up, but the responseText property is empty, even when the JSON file is not. The JSON file is 35Kb and I did test what could happend if I shorten it a bit. I've seen that, if the JSON file is a small one I don't have this problem. Is there a limit about how much data can the responseText property can hold?

APP Type: Mobile Ti SDK: Build: 2.1.0.201206251749 | jenkins-titanium-rcp-master-218 (origin/master) Platfrom: Android Version: 2.2 Device: Emulator Host: Debian x64

var httpClient = Ti.Network.createHTTPClient({
            timeout: 5000,
            onload: function( e ) {
                alert( this.getResponseText() );//this.responseText is empty too
            },
        });
httpClient.open( 'GET', 'url.bla.bla' );//url is valid, just a private one.
httpClient.send();
JSON file contents: (Working)
{"canales":[{"grupo":"uchile.4.2005.0.ADI001.1","autor":"13047454","fecha":"2012-06-15 12:24:59","serv_nombre":"Material Docente","serv_nombre_interno":"material_docente","serv_url":"https://adi2.ing.uchile.cl/~andregon/ucursos/ucursos/uchile/2005/0/ADI001/1/material_docente/","titulo":"GUIA completo.txt","mensaje":"GUIA completo.txt","url":"https://adi2.ing.uchile.cl/~andregon/ucursos/ucursos/uchile/2005/0/ADI001/1/material_docente/objeto/375331"}]}
If the above entry (everything between []) is repeated 90 times (which is the times on the actual file) the responseText is empty.

4 Answers

Try

this.responseText
instead of
this.getResponseText()
I have run into a number of situations on android where the getter function doesn't work (on various different objects and properties throughout Titanium), but direct access to the property does work.

— answered 10 months ago by Jason Priebe
answer permalink
9 Comments
  • As I said (marked as a comment in the code)

    this.responseText
    and
    this.getResponseText()
    are both empty.

    — commented 10 months ago by Andres Gonzalez

  • Sorry -- I missed that.

    Can you put a short file (that works) and a long file (that doesn't work) on a public web server somewhere and create a one-file app.js example that demonstrates the problem?

    — commented 10 months ago by Jason Priebe

  • I'll do so in a few minutes, but it's quite the same that it's already here. A generic HTTPClient usage and either a small (455bytes, working, just like the one in the example) or a big (35Kbytes, repeating

    {"grupo":"uchile.4.2005.0.ADI001.1","autor":"13047454","fecha":"2012-06-15 12:24:59","serv_nombre":"Material Docente","serv_nombre_interno":"material_docente","serv_url":"https://adi2.ing.uchile.cl/~andregon/ucursos/ucursos/uchile/2005/0/ADI001/1/material_docente/","titulo":"GUIA completo.txt","mensaje":"GUIA completo.txt","url":"https://adi2.ing.uchile.cl/~andregon/ucursos/ucursos/uchile/2005/0/ADI001/1/material_docente/objeto/375331"}
    90 times will do).

    — commented 10 months ago by Andres Gonzalez

  • Show 6 more comments

Can you try and increase the timeout? Or even remove it, to see if that has any effect?

— answered 10 months ago by Pallavi Sivakumaran
answer permalink
10 Comments
  • Increasing the timeout, or not declaring it, has show no change in the behavior.

    — commented 10 months ago by Andres Gonzalez

  • I don't know whether or not this would make any difference, but there's a Parse error on line 1022 in the JSON object (according to http://jsonlint.com): "titulo": "Roberto Meza: "LaLeySOPAeInternet"",

    Maybe correcting this would fix the issue?

    — commented 10 months ago by Pallavi Sivakumaran

  • I think it would do if I parse the JSON file (which I was planning to do later), but instead of a parsing error I just get an empty responseText. I'll try fixing that and see what happens.

    — commented 10 months ago by Andres Gonzalez

  • Show 7 more comments

Just wondering if you can get it to work outside of the Titanium Environment? Have you tried just doing the same request in a browser to see if it works. I always seem to find my mistakes that way.

— answered 10 months ago by Lee Bartelme
answer permalink
1 Comment
  • If i just open the url of the JSON file in a browser, it works just fine, and our ajax functions get the file too.

    — commented 10 months ago by Andres Gonzalez

In the end, was a matter of encodings between the server, the file and the httpClient. I didn't notice the error line in the console, so I'm the one to blame here. :P

Anyway, moral of the story: double check ALL the encodings!

— answered 10 months ago by Andres Gonzalez
answer permalink
2 Comments
  • An onerror method with an alert could have saved you some time also.

    — commented 10 months ago by Darren Adams

  • Well onerror is not fired by this. I did had it implemented.

    — commented 10 months ago by Andres Gonzalez

Your Answer

This question has been locked and cannot accept new answers.