Skip to main content
Inspiring
Jun 4, 2020 1:53 PM UTC
Question

POST request working through postman but not through code

Hello Community,

I am trying to write a folder level js script in acrobat pro that makes a HTTP post request to a server. It requires the value of the SSO token as the header in the request. When I made the request using postman by adding a header in the request as key="Cookie" and value="SSO=....;", it successfully hit the server and returned a response. On the other hand, when I tried to do it using the below code, it doesn't seem to hit the server and gets a redirection. I am not able to figure out what's the issue. Any help regarding this would be greatly appreciated.

Thanks.

 

ajax=app.trustedFunction(function(furl)){
app.beginPriv();
Net.http.request({
cVerb: "POST",
cURL: furl,
aHeaders: [ { name: "Cookie" , value: "SSO=....;" }],
oHandler: callbackfn
});
app.endPriv();
});

callbackfn = {
response : function(...){
...
}
};

ajax("https://...");

 

 

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

14 replies

nishant13Author
Inspiring
Jun 21, 2020 7:19 AM UTC

Could anyone help with more inputs as to why is acrobat behaving strangely with the cookie?

Translate
Thom Parker
Community Expert
Community Expert
Jun 24, 2020 4:51 PM UTC

Is there a cross domain issue?

 

https://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Legend
Jun 5, 2020 7:31 AM UTC

What do you mean “gets a redirection”? 

Translate
nishant13Author
Inspiring
Jun 5, 2020 9:51 AM UTC

I mean it doesn't hit the intended URL because of something and the URL is made such that the incomplete request gets a redirection to some other URL(like login page).

Translate
Legend
Jun 5, 2020 10:08 AM UTC

So you are trying to get to s page that needs login. And it hits the server but the server doesn’t pass it on. The whole idea of bypassing login with cookies is very suspect. Your front end probably does some security tests like cookie origin, cross domain checks or whatever. Maybe it sends challenge/response. We can’t know and external inspection can’t find out. If one could just copy cookies to bypass login the internet would be a very unsafe place. You need to liaise with your server developers to find a secure route for whatever thing you must do. 

Translate
Thom Parker
Community Expert
Community Expert
Jun 4, 2020 6:43 PM UTC

Are you sure that the request from Acrobat has all of the required headers? Is the empty body a problem?

 

Have you been able to successfully post to a site that does not require cookies?  

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
nishant13Author
Inspiring
Jun 5, 2020 7:29 AM UTC

No, the empty body is not the problem because through postman  I am able to successfully make the request using an empty body. Also, I have been able to successfully post to a URL that does not require cookies. 

For the 'all required headers' thing, would I need to pass all the headers that are appearing in the request headers under postman including "User-Agent", "Cache-Control" etc?

Translate
Thom Parker
Community Expert
Community Expert
Jun 6, 2020 9:05 PM UTC

Not all of the cookies are necessary, but some are, such as content-type. I don't know exactly what's needed, but browsers add a lot to an HTTP request, and afik the net.http request only adds the content length.  So I'd suggest you put it all in, and also check for any kind of hand shaking. 

 

But TestScreen is correct that this seems like a security problem. Usually, there is some kind of authorization process for getting onto a secure site. These days everything is REST. I'd talk to the site developers to find out the proper way to do this. 

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