Skip to main content
Inspiring
Jun 3, 2020 12:53 PM UTC
Question

'POST' document to server using javascript along with header cookies

Hello all,

I have been given a task to write a JS script in acrobat pro to POST the complete pdf document currently opened to a server. Also, I need to send some particular cookie along with the request("Cookie" = "...") because of the redirection to the login page of our organization. I know a method of  'doc' object to post the complete pdf document 'submitForm()' but I cannot figure out how can we send that cookie(name, value) thing(if possible using submitForm()). I don't know about any other method. Any help regarding this would be greatly appreciated.

Thanks.

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Thom Parker
Community Expert
Community Expert
Jun 3, 2020 4:22 PM UTC

It is not possible to set the HTTP Request header values with the "doc.submitForm()" function.  The whole point of this function is to submit form data in a secure way. This is not a general purpose HTTP tool. The "secure" part is supposed to mean the user can trust the PDF not to do any not nice things, so this function is boxed into a particular usage model. 

 

Adding cookies to a submit that would allow it to circumvent your organization's security seems like a not so nice thing. What would happen if a malicious user got ahold of this PDF?

 

The way to get around this issue is to provide an authentication mechanism or limited usage model by submitting to a server script outside the security wall, and have it do whatever transactions need to be done. 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
nishant13Author
Inspiring
Jun 3, 2020 5:15 PM UTC

Is there any way to POST using general javascript functions or using something like fetch API. Also I know of one more function net.http.request(), is it possible using this because it has a parameter aHeaders through which we can send perhaps?

Translate
Thom Parker
Community Expert
Community Expert
Jun 3, 2020 9:55 PM UTC

Yes, this can be done with net.http.request(), but only from a folder level trusted function. The security notes in the reference entry for this function indicate that it cannot be executed in the context of a document. So I'm not even sure if it would work for privileged document. 

 

If you can install a folder level function on the user's system, then you can use net.http.request(). If not then the proxy server script solution I proposed is your only option.  

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often