Titanium Community Questions & Answer Archive

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

Passing parameters with HTTP Client, double encoding!

I am using Ti.Network.createHTTPClient to pass some info to a PHP page, for example:

var email = "john@website.com";
var encodedEmail = encodeURIComponent(email);
this.HTTPClient.open('GET', someAddress + "?email=" + encodedEmail);
this.HTTPClient.send();

This works fine on the Simulator and on my iPod Touch. However, when I test on an iPhone, when the PHP page receives the email variable, it's been encoded twice! Does anyone know what might be causing that?

I've noticed that for some reason, the iPhone is reporting a TitaniumVersion of 1.2, while the iPod reports a TitaniumVersion of 1.4, and I suspect this might be the cause. But I definitely have 1.4 selected in my Project settings, so I have no idea why the iPhone reports 1.2. Any guesses would be appreciated!

— asked September 1st 2010 by Mike Dosey
  • 1.2
  • 1.4
  • decode
  • encode
  • httpclient
  • iphone
  • ipod
  • php
  • titaniumversion
0 Comments

4 Answers

  • Accepted Answer

    I have no solution for you as yet, but I'm pretty sure it's Ti API 1.4 related. I have a bunch of code I wrote under 1.2 and 1.3 API levels using some AJAX gets, and now all of a sudden it stopped working when I upgraded to 1.4.

    I tracked it down to the same double encoding problem. My " in my QS args are showing up in apache logs as %2522, it should just be %22 (25 is hex for %, 22 is hex for ").

    I'd say this is pretty highly likely a 1.4 bug, and indeed the problem also goes away for me if I post instead.

    — answered September 22nd 2010 by Jonathan Mason
    permalink
    0 Comments
  • If anyone has a guess as to why the iPhone is double-encoding parameters of the HTTPClient URL, while the iPod touch is not, I'd definitely appreciate any help!

    — answered September 2nd 2010 by Mike Dosey
    permalink
    0 Comments
  • Having a similar problem over here :(

    I'm trying to make a call to the bit.ly API but both: Titanium.Platform.openURL and Titanium.Network.createHTTPClient are acting weird.

    For example, the link http://w3schools.com/my test.asp?name=ståle&car=saab should be fully escaped to http%3A%2F%2Fw3schools.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab

    I can easy do this calling the encodeURIComponent() function but then for some weird reason, when I pass over the output to the Titanium.Network.createHTTPClient I'm having the last bit cut it off

    &car=saab

    (something that not happen if I run the same url directly in the browser).

    This is the response from the API:

    { "status_code": 200, "status_txt": "OK", "data": { "long_url": "http:\/\/w3schools.com\/my test.asp?name=st\u00e5le", "url": "http:\/\/bit.ly\/c317XX", "hash": "c317XX", "global_hash": "aC38MP", "new_hash": 0 } }

    as you can see the last part of the url is missing.

    — answered September 13th 2010 by Joe Maffia
    permalink
    0 Comments
  • I ended up using POST submission rather than GET, to avoid the issue. Not sure if that will help in your case or not, though.

    — answered September 13th 2010 by Mike Dosey
    permalink
    1 Comment
    • mhhh weird… I'll give a try anyway.

      Thanks.

      — commented September 14th 2010 by Joe Maffia
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.