Code: Select all
sendEvent({id: id, event: this}, httpSucess, httpError, httpComplete);
function sendEvent(jsonData, successCb, errorCb, completeCb) {
console.log("HTTP Post - " + JSON.stringify(jsonData));
http.request({
method: 'POST',
url: "[insert url here]",
header: {
"Content-Type": "application/json"
},
contentType: "application/json",
data: jsonData,
async: true,
success: successCb,
error: errorCb,
complete: completeCb
});
}
1. If I send the object as is, the "this" object is turned into a string as [object DataHoldObj] (or something similar). The actual JSON object is not sent. I have worked around this by using {id: id, event: JSON.stringify(this)} instead. I then parse the JSON event on the server side. I think this happens because the post is sent via url encoded parameters. Is there a way to post raw data?
2. The server receives the Content-Type parameter in the header as application%2Fjson. I know this is because it is being URL encoded, but I don't think the headers need to be encoded. Correct?