Making 'POST' request using Javascript
Hello Community,
I am a beginner in developing acrobat functionalities. I have written a folder level script to make a submenu in adobe acrobat pro which when pressed makes a POST request to a dummy server. I have been able to make GET requests without no problem but for POST requests I keep getting the following error :
"NotAllowedError: Security settings prevent access to this property or method" in the following code which I have taken from https://gist.github.com/randycasburn/802f278c3cfef0873dd086c34bbb9fee to make post requests. Any kind of help regarding this would be highly appreciated.
Thanks.
Edit : After reading some responses I have edited to make those required changes. But still, I am getting error.
Here is the code:
// Make HTTP POST request
ajax = app.trustedFunction(function(fURL,doc) {
// Create some Stream object:
strObj = doc.createDataObject("myData", "This is the data");
app.beginPriv();
Net.HTTP.request({ cVerb:"POST", cURL:fURL, oRequest: strObj, oHandler: ajaxCallback});
app.endPriv();
});
// process the response
ajaxCallback = {
response:function(msg,uri,e){
var stream = msg;
var string = "";
var error = e == undefined? 'No HTTP errors' : "ERROR: " + e.toSource();
string = SOAP.stringFromStream( stream );
oResult = JSON.parse(string);
console.println(error);
console.println( "id: " + oResult.id);
console.println( "userId: " + oResult.userId);
console.println( "title: " + oResult.title);
console.println( "body: " + oResult.body);
}
};
// Add menu item to kick it all off
app.addMenuItem({
cName: "Get Mock Data", cParent: "File",
cExec: 'ajax("https://jsonplaceholder.typicode.com/posts/1", this);',
nPos: 0});
