Copy link to clipboard
Copied
I referenced the Javascript documentation and tried using a Net.HTTP.request. The documentation only shows an example of how to do an MKCOL request, not a GET request.
If I hard-code the cURL value, I get the value "undefined". If I try passing it through a variable (as in the example below), I get the error "Invalid Arguments".
My code looks something like this:
foo = app.trustedFunction(function (cURL) {
app.beginPriv();
var params = {
cVerb: "GET",
cURL: cURL,
oHandler: {
response: function (msg, uri, e) {
var stream = msg;
var string = "";
string = SOAP.stringFromStream(stream);
console.println(string);
console.println(stream);
}
}
};
Net.HTTP.request(params);
app.endPriv();
});
foo("http:/api.somesite.com/data?q=param&apikey=123xyz&mode=xml");
(I didn't try passing data to the form yet, but just tested out the code by printing to the console first).
I am assuming that the variables in the response function (msg, uri, e) are populated by the response from the server? I am not quite sure how to "grab" the data that I want, and why I am getting these errors. Also wondering if I can do it without using SOAP. Thanks in advance!
Copy link to clipboard
Copied
In three weeks with 45 views, no one has answered my post. I would really appreciate someone providing an answer, even if the answer is "it can't be done". I have not found a solution to my problem. Please help!
Copy link to clipboard
Copied
Using the NET interface is not something a lot of people do, that's very likely why you have not received a response yet. Take a look here for at least another sample: Getting a Serial Number Into a Form Using SOAP - KHKonsulting LLC
If you want to do this without SOAP, I just published a new post about using XFDF to get data from a form or into a form: Connect to Database from PDF Form - This Time Without SOAP - KHKonsulting LLC
Copy link to clipboard
Copied
Hi Karl, thanks for your reply and for referring me to your posts!
Your example using XFDF looks very interesting.. However, it will not work for my situation. I'm not trying to connect to my own server, but a third-party server throught their API. So I won't be able to write php on their server.
Yes, I want to avoid using SOAP because I want the code to run in Adobe Reader, not just Acrobat, as your first post points out.
So is there really no one that can show me how to do this with the Net.HTTP.request?
Copy link to clipboard
Copied
If an error occurs then Net.HTTP.request still calls on the response handler. Try the following: 1. Include the check for error in your response then try again. 2. If you get an error type “NetworkError” then make sure the url is correct and there are no hidden characters or control characters in the url. The method util.stringFromStream is probably an alternative to SOAP.stringFromStream. Reference Adobe Systems Incorporated. (2007). Net.HTTP and util.stringFromStream (pp. 544 – 556; 743 – 744). In Adobe Acrobat SDK 8.1 JavaScript for Acrobat API Reference for Microsoft Windows and Mac OS. Edition 2.0, April 2007. San Jose, California: Adobe Systems Incorporated. Retrieved Aug. 3, 2010 from DC Developer Resources.
Copy link to clipboard
Copied
Thanks, John! I figured out the reason I was getting the error "undefined" - it was because I was missing a slash in the URL.
I tested out using util instead of SOAP and it works in Adobe Acrobat. I will get back to you again once I test it in Reader.
Copy link to clipboard
Copied
Hold on a sec... The documentation that John referenced is from 2007, but Karl referenced the SDK documentation (which I didn't even know existed, LOL) from 2015. His article states that Net.HTTP requires a LiveCycle Extension to support in Acrobat Reader.
I found this article which expands on Karl's post regarding this matter: Adobe LiveCycle Designer: Working with PDF and Acrobat
It states:
Although Reader extending with Acrobat Professional is good for many cases, you’ll have to extend your forms with LiveCycle Reader Extensions if you need Reader users to access any of the following functionality in your XFA PDFs:
- Connecting to data in real time
- Using barcodes
- Attaching files
Therefore, since I require the form to connect to data in real time, I won't be able to do this with Acrobat Pro DC. util only substitutes SOAP inside the Net.HTTP.request, so it will be subject to the requirements.
I will be looking into another solution right now, and once I do, I will come back and post again.
Thanks again Karl Heinz Kremer and John Frederick Chionglo for your answers, they have helped me better understand the issue, even if I can't resolve it
Copy link to clipboard
Copied
You may have to create a server-side solution that can translate between your 3rd party solution (that uses SOAP) and XFDF (so that you can allow Reader to retrieve and submit data).
Copy link to clipboard
Copied
Did you ever figure this out? I am currently trying to do the same thing it seems. This is where I am so far: Pulling JSON data from a third party web API to fill PDF's form fields (thanks to help from your post)
Copy link to clipboard
Copied
Hi, @Nirvana87$ . Sorry for the late reply! I don't recall getting an email notification for your comment and am just seeing it now.
I think @Karl Heinz Kremer had a good suggestion. Unfortunately, a server-side solution was not going to work for my use case. I did not find another solution 😞
I hope that you were able to find something that worked for you!
Copy link to clipboard
Copied
Hello Burton,
I'm sorry you have been waiting on this for so long, and I didn't see the message. I've used the .Net HttpRequest functionality quite a lot. It has limitations, for example there is no access to the return headers. But it handles the return data quite well. One of the tricks to using it properly is to set the correct hearder fields.
But really, you need to first build a test framework, so you can see what's going on with the HTTP operations. I used local server PHP for this. And on the Acrobat side I built a dialog based automation tools, which you can get here:
HTTP Access Tester - Description
Copy link to clipboard
Copied
Hi, @Thom Parker ! Thanks for your reply 🙂
I'm no longer working on that project, but maybe your answer will be helpful to someone else. Maybe it might help @Nirvana87$ , who had a similar post recently.
Copy link to clipboard
Copied
"undefined" is not an error, it's a value, often normal. If you do get an error, please show your error messages in full (they give more info and give a line number - point us to the line given). If it's printed by itself, it's probably what is passed to your response callback.
The response from the request is passed to the function you define. So, msg, url and e are defined in that function - and nowhere else. If you want to read those values later you have to copy them somewhere.
Copy link to clipboard
Copied
I think the problem lies which level you put your script. This gist, This makes a HTTP GET request from within Adobe Acrobat · GitHub, has a sample with a warning 'This file must be placed with the user JavaScript file location or the Acrobat JavaScript file location.', which is same as the note in the official SDK for Net.HTTP methods (Acrobat DC SDK Documentation (adobe.com)), 'This method can only be made outside the context of a document (for example, in a folder level JavaScript).'