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
1 Answer
-
I've found that on Android at least (I haven't done iPhone yet) you'll need to do the following:
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.
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.