Titanium Community Questions & Answer Archive

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

How to pass a null parameter to HTTPRequest ?

Hello,

I'm trying to send a request, sometimes with parameters, sometimes without.
So i pass a json object to the send method.
But sometimes data is empty and the request is not sent. Everything works fine on iPhone but not on android.

Example :

var data = {};//it works
var data = {login: 'titi',password: 'toto'};//it works

Then, i only have to send : xhr.send(data);

If i pass a string, it doesn't work.

Thanks for your help.

Matthieu

— asked September 28th 2010 by matthieu pascaud
  • android
  • http
  • httpclient
  • httprequest
  • mobile
0 Comments

1 Answer

  • I've found that on Android at least (I haven't done iPhone yet) you'll need to do the following:

    1. HTTPClient won't send the request if there are any values that are null. If a JSON object has null properties, be sure to either remove the property from the JSON object or covert it to an empty string.

    2. If you're sending data using an object, be sure to use the POST method. If you are not sending any data, be sure to use the GET method.

    I've actually encapsulated HTTPClient usage into my own little function. If you do the same and then check the data object passed to that function, and make changes accordingly.

    — answered September 29th 2010 by Ryan Asleson
    permalink
    1 Comment
    • It's what I did but i think it's a bug present on the android version because it works well on iPhone. But thanks for your help, at leat, we had the same idea.
      It can also help you if you plan to work on iPhone : if you encode (percent encoding) your url (oauth request) and send it by using the GET method, the url is re-encoded on iPhone so will not get the expected result.

      — commented September 29th 2010 by matthieu pascaud
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.