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!
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.
-
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!
-
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.
-
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.