Reputation: 658
I want to get data from server using post method. In my cordova application I am using this Cordova HTTP plugin. But I really not understand that tutorial. I want to send email id & password in header and get data from server for this I am using following code.
cordovaHTTP.post("https://google.com/", {
id: 12,
message: "test"
},{ Authorization: "OAuth2: token" }, function(response) {
// prints 200
console.log(response.status);
try {response.data = JSON.parse(response.data);
// prints test
console.log(response.data.message);
} catch(e) {
console.error("JSON parsing error");
}}, function(response) {
// prints 403
console.log(response.status);
//prints Permission denied
console.log(response.error);
});
Please modify above code and use demo variable for understand.
Upvotes: 1
Views: 1424
Reputation: 2546
You do realise in this code you are posting to google. a post
is a client server "event" you are (here) the client. but your "server" is google and that is not gonna work because google main home page is going to get a message saying id=12&message=test and google is gonna just go whaaaaaaaaaaaaaa and send you nothing of use - certainly not a usable json string (which this code needs)
Upvotes: 1