HTTP Client input - GET pdf from HTTPS server

I’m on Connect 2019.2 and am attempting to use the HTTP Client input task to retrieve PDF files from a remote HTTPS server.

When attempting this I receive the following error:
[0003] W3730 : Error resolving the URL : Error connecting with SSL.

Is the HTTP Client capable of retrieving files via HTTPS?

I tried using it against a couple of the PDF files on the OL Connect help site and got the same error.

For example, if I try to download this PDF file via the HTTP Client I get the error:

The help file for the HTTP Client mentions HTTPS is supported.

Is there a way to do this with the HTTP Client task? Or do I need to shift to scripting cURL or similar utility?

Thanks!

I confirm this issue.

Probably because the remove site doesn’t support SSL (it’s been deprecated for a while, but that plugin still uses it).

The following script will achieve what you want:

var xhr = new ActiveXObject("Microsoft.XMLHTTP");
xhr.open("GET","https://help.objectiflune.com/en/planetpress-workflow-user-guide/2019.2/planetpress-workflow-user-guide.pdf",false);
xhr.send();

var binaryStream = new ActiveXObject("ADODB.Stream")
binaryStream.Type = 1;
binaryStream.Mode = 3;
binaryStream.Open();
binaryStream.Write(xhr.responseBody);
binaryStream.SaveToFile(Watch.GetJobFileName(),2);
binaryStream.Close();
1 Like

Hi Phil,

I am getting the same Error as above when using the HTTP Input Client to try to download a PDF from a URL that requires Authentication.

Could your script above be modified to pass credentials to the download site?

Thanks!

If the server accepts Basic Authentication, then all you have to do is add the following line immediately before the xhr.send(); line:

xhr.setRequestHeader("Authorization", "Basic " + btoa(USER_NAME+":"+USER_PASSWORD));

Make sure your script language is set to Enhanced JScript (i.e. not the standard JScript, which does not implement the btoa() method).

And, obviously, set the USER_NAME and USER_PASSWORD values to match your credentials.

1 Like

How about if they client-id and client-secret?
Any idea what it should be then?

If the server is specifying that Basic authentication is supported, than client-id and client-secret are just synonyms for username/password.

But my guess is that the server requires a different kind of authentication.

Yes, it is different but I have it working for the most part.
Just need to get the variable into the setRequestHeader, but it seems to fail regardless of how I build the string.

  var CLIENTID =  Watch.GetVariable("global.ClientID");
  xhr.setRequestHeader('client-id', 'Insert CLIENTID here');

It seems to fail” doesn’t give me much to go on.
The syntax you are using appears correct, assuming you meant to write something like this:

var CLIENTID =  Watch.GetVariable("global.ClientID");
xhr.setRequestHeader('client-id', CLIENTID);

But without additional context, I can’t help you much. Here’s a couple of pointers, though:

  • Make sure you use setRequestHeader() after the open() and before the send() calls.
  • When a client-id/client-secret are embedded in request headers like this, it is almost certain that the URL requires you to use https (not http). Check with the documentation of the server you are attempting to reach.

Sorry forgot to update.

I did get it to work, but not sure why. I deleted the lines and typed them in. The command did evolve and at some point I had used cut & paste with the values, so I guess there was a hidden character somewhere.

var CLIENTID = Watch.GetVariable("global.ClientID");
var CLIENTSECRET = Watch.GetVariable("global.ClientSecret");

xhr.setRequestHeader('client-id', CLIENTID);
xhr.setRequestHeader('client-secret', CLIENTSECRET);

:ok_hand:

Glad to see it works now.