Calling webservice from online returns HTTPConnection::endRequest(): Failure when receiving data from the peer

After moving our installation from onsite to online I'm unable to get data from a http webservice.
It works fine onsite and it responds well from Postman on my local PC.
At the endpoint there's no traces of connection from Superoffice Online.

I've extracted the essential part of the script:

%EJSCRIPT_START%
<%
#setLanguageLevel 3;
#include "lib-http";

//Hent ut forhandlerinformasjon til nettsidene
//In a browser, go to: (online-url)/CS/scripts/customer.exe?action=safeParse&includeId=getForhandleroversikt&key=xxxxxxxxxxxxxxx

HTTP httpPostnummer;
httpPostnummer.setOption("username", "xxxxxxxxxx");
httpPostnummer.setOption("password", "xxxxxxxxxx");
httpPostnummer.setOption("charset", "utf-8");
httpPostnummer.setDebugMode(true);
String json = String(httpPostnummer.get("https://sande.erling-sande.no:20089/superofficeApi/hentPostnummer?postnummer=9010"));
printLine("getDebug: " + httpPostnummer.getDebug());
printLine("");

printLine("responseHeaders:");
Map responseHeaders = httpPostnummer.getResponseHeaders();
for (responseHeaders.first(); !responseHeaders.eof(); responseHeaders.next())
{
printLine("header: " + responseHeaders.getKey() + " => " + responseHeaders.getVal());
}
printLine("");

printLine("getErrorMessage:" + httpPostnummer.getErrorMessage());
%>
%EJSCRIPT_END%

 

This is my response:

getDebug:

responseHeaders:
header: connection => keep-alive
header: content-language => en
header: content-length => 3243
header: content-type => text/html;charset=utf-8
header: date => Wed, 05 May 2021 06
header: http/1.1 403 forbidden =>
header: mime-version => 1.0
header: server => squid
header: vary => Accept-Language
header: via => 1.1 prod_proxy_blacklist (squid)
header: x-cache => MISS from prod_proxy_blacklist
header: x-cache-lookup => NONE from prod_proxy_blacklist
header: x-squid-error => ERR_ACCESS_DENIED 0

getErrorMessage: HTTPConnection::endRequest(): Failure when receiving data from the peer

RE: Calling webservice from online returns HTTPConnection::endRequest(): Failure when receiving data from the peer

From the error message in the header, this seems to be "squid", which is a proxy software, blocking your request.

My guess is that the custom port number you are using (20089) for the endpoint is the problem. I think that only a limited number of ports are open in Online. 

Are you able to change the port number that the API are listening to?

By: Stian Andre Olsen 5 May 2021

RE: Calling webservice from online returns HTTPConnection::endRequest(): Failure when receiving data from the peer

Not without some effort. There are several other applications using the endpoints at this port...

By: Espen Rønning 5 May 2021

RE: Calling webservice from online returns HTTPConnection::endRequest(): Failure when receiving data from the peer

The problematic script's job is to provide our webpages with an array of dealers information.  95% of this information is present in SuperOffice, but unfortunatly some of it are not (I'm missing city code, county and county number). This information needs to be obtained from my ERP-system.

I guess the easiest way to fix this is to create a new end point at my side. This enpoint can extract the information stored in SuperOffice (without fetching any extra data with HTTP), and then supply the missing data before returning the result to our webpages.

Anyway, it would be nice to know witch ports are availeble for HTTP in online scripts.

By: Espen Rønning 5 May 2021

RE: Calling webservice from online returns HTTPConnection::endRequest(): Failure when receiving data from the peer

Hi Espen, 

only outgoing ports 80 and 443 are open from Online. Ref this thread, and this documentation.

By: Frode Lillerud 5 May 2021

RE: Calling webservice from online returns HTTPConnection::endRequest(): Failure when receiving data from the peer

Hi Espen,

Just a little note, if you included the key by mistake in the copied code, please change it in your solution. :)

Best Regards
Marcus

By: Marcus Svenningsson 5 May 2021

RE: Calling webservice from online returns HTTPConnection::endRequest(): Failure when receiving data from the peer

Ah - thanks. Code is changed.

By: Espen Rønning 5 May 2021