Posting data using Javascript Net.HTTP
Posted: Wed Feb 06, 2019 2:00 am
I'm using Javascript in PDF-XChange Editor to post information to a web service where it is read using php. It's all working great except I can't work out how to successfully post my data in the body of the post, using the oRequest parameter, and read it using php on the server. The only thing I could get to work is posting in the header using a redundant header field (I picked PRAGMA). This is obviously far from ideal.
This is my Javascript triggering the post (I want to use oRequest but instead have to use aHeaders):
postData = app.trustedFunction(function(f) {
app.beginPriv();
var urlStr = "http://mywebsite.com/postdata.php"
Net.HTTP.request({
cVerb: "POST",
cURL: urlStr,
// oRequest: util.streamFromString(JSONstr),
aHeaders:[{ name: "PRAGMA", value: syncs[f].JSONstr }],
oHandler: ajaxCallback
});
app.endPriv();
});
This is my php on the server (I want to use the first line, but have to use the second):
// $dataPOST = file_get_contents('php://input');
$dataPOST = $_SERVER['HTTP_PRAGMA'];
Is there something I'm doing wrong here?
This is my Javascript triggering the post (I want to use oRequest but instead have to use aHeaders):
postData = app.trustedFunction(function(f) {
app.beginPriv();
var urlStr = "http://mywebsite.com/postdata.php"
Net.HTTP.request({
cVerb: "POST",
cURL: urlStr,
// oRequest: util.streamFromString(JSONstr),
aHeaders:[{ name: "PRAGMA", value: syncs[f].JSONstr }],
oHandler: ajaxCallback
});
app.endPriv();
});
This is my php on the server (I want to use the first line, but have to use the second):
// $dataPOST = file_get_contents('php://input');
$dataPOST = $_SERVER['HTTP_PRAGMA'];
Is there something I'm doing wrong here?