cordovaHTTP.post not working as expected

Ask, and ye shall receive.
subhakanth
Posts: 2
Joined: 20:57, 01 Mar 2016

cordovaHTTP.post not working as expected

Postby subhakanth » 21:11, 01 Mar 2016

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

alex
Posts: 92
Joined: 00:59, 19 Nov 2013

Re: cordovaHTTP.post not working as expected

Postby alex » 22:28, 01 Mar 2016

Hi!

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

Sometimes your eyes plays tricks om you!

Axl

subhakanth
Posts: 2
Joined: 20:57, 01 Mar 2016

Re: cordovaHTTP.post not working as expected

Postby subhakanth » 22:44, 01 Mar 2016

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

alex
Posts: 92
Joined: 00:59, 19 Nov 2013

Re: cordovaHTTP.post not working as expected

Postby alex » 15:24, 13 Mar 2016

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?


Return to “Questions and answers”

Who is online

Users browsing this forum: No registered users and 6 guests