Page 1 of 1

cordovaHTTP.post not working as expected

Posted: 21:11, 01 Mar 2016
by subhakanth
Hello All,
Apologies if this kind of question is asked earlier. I tried searching but was not successful.

I copied the code of 'TI SensorTag CC2650 & CC2541 Sensors' and trying to enhance it.

I wanted to send the temperature data from sensor to an oData service being hosted on SAP Hana Cloud Platform.

The following is the my code. For now I hardcoded the values.
Note: I replaced the 'Bearer' code with all 'x....'
------------------------------------------------------------------------------------------------------------------------

cordovaHTTP.setHeader("Content-Type", "application/json;charset=utf-8" , function() {
alert(response.status);
}, function() {
alert(response.status);
});

cordovaHTTP.post("https://iotmmsi074490trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data/5432d276-2573-4edc-9b47-0c1a26438db6",
{ "mode": "async","messageType": "6988e4f679b44b20a6f8","messages": [{"temperature": "23.00","humidity": "64.00"}] },
{Authorization : "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, function(response) {
// prints 200
alert(response.status);
try {
response.data = JSON.parse(response.data);
// prints test
alert(response.data.message);
} catch(e) {
alert("JSON parsing error");
}
}, function(response) {
// prints 403
alert(response.status);

//prints Permission denied
alert(response.error);
});
------------------------------------------------------------------------------------------------------------------------

I always get a response 400. I have always trouble with JSON string. My server always seems to receive JSON string like below i.e., the formatting and quotes(") were lost.

messageType=6988e4f679b44b20a6f8&messages[][humidity]=64.00&messages[][temperature]=23.00&mode=async

Can you please guide me and suggest what I am missing.

I tried the same posting using postman client and it is working.

Thank you.

- Subhakanth

Re: cordovaHTTP.post not working as expected

Posted: 22:28, 01 Mar 2016
by alex
Hi!

Is it as simple as "Authorization" needing quotes to be well-formed json?

Sometimes your eyes plays tricks om you!

Axl

Re: cordovaHTTP.post not working as expected

Posted: 22:44, 01 Mar 2016
by subhakanth
Hi Alex,
Thanks for the quick reply.

But unfortunately the tip you have give did not help. I am still facing the same issue.

Any other suggestions?

Thanks.

Best regards,
Subh

Re: cordovaHTTP.post not working as expected

Posted: 15:24, 13 Mar 2016
by alex
Hi! I see you didn't get more replies, did you figure out if it was the server which was acting up, or something else?