include "gethttp.s7i";
include "tls.s7i";
const func file: openHttps (in httpLocation: locationData) is func
result
var file: sock is STD_NULL;
begin
if locationData.httpsProtocol then
sock := openTlsSocket(locationData.serverName, locationData.portNumber);
else
sock := openInetSocket(locationData.serverName, locationData.portNumber);
end if;
if sock <> STD_NULL then
sendGet(sock, locationData);
end if;
end func;
const func file: openHttps (in string: serverName, in integer: serverPortNumber,
in string: location) is func
result
var file: sock is STD_NULL;
local
var httpLocation: locationData is httpLocation.value;
begin
locationData := getHttpLocation(location, httpsDefaultPort);
locationData.httpsProtocol := TRUE;
locationData.serverName := serverName;
locationData.portNumber := serverPortNumber;
sock := openHttps(locationData);
end func;
const func file: openHttps (in string: location) is func
result
var file: sock is STD_NULL;
local
var httpLocation: locationData is httpLocation.value;
begin
locationData := getHttpLocation(location, httpsDefaultPort);
locationData.httpsProtocol := TRUE;
if proxyServer <> "" then
locationData.serverName := proxyServer;
locationData.portNumber := proxyHttpPort;
end if;
sock := openHttps(locationData);
end func;
const func string: getHttps (in string: serverName, in integer: portNumber, in string: location) is func
result
var string: data is "";
local
var httpLocation: locationData is httpLocation.value;
var file: sock is STD_NULL;
var string: statusCode is "";
var boolean: okay is TRUE;
var integer: repeatCount is 0;
begin
locationData := getHttpLocation(location, httpDefaultPort);
locationData.httpsProtocol := TRUE;
locationData.serverName := serverName;
locationData.portNumber := portNumber;
repeat
okay := TRUE;
sock := openHttps(locationData);
if sock <> STD_NULL then
statusCode := getHttpStatusCode(sock);
if statusCode = "301" or statusCode = "302" or
statusCode = "303" or statusCode = "307" then
locationData := getHttpLocation(locationData, sock);
close(sock);
sock := STD_NULL;
okay := FALSE;
incr(repeatCount);
end if;
end if;
until okay or repeatCount > 5;
if sock <> STD_NULL then
data := getHttp(sock);
close(sock);
end if;
end func;
const func string: getHttps (in string: location) is func
result
var string: data is "";
local
var httpLocation: locationData is httpLocation.value;
var file: sock is STD_NULL;
var string: statusCode is "";
var boolean: okay is TRUE;
var integer: repeatCount is 0;
begin
locationData := getHttpLocation(location, httpsDefaultPort);
locationData.httpsProtocol := TRUE;
if proxyServer <> "" then
locationData.serverName := proxyServer;
locationData.portNumber := proxyHttpPort;
end if;
repeat
okay := TRUE;
sock := openHttps(locationData);
if sock <> STD_NULL then
statusCode := getHttpStatusCode(sock);
if statusCode = "301" or statusCode = "302" or
statusCode = "303" or statusCode = "307" then
locationData := getHttpLocation(locationData, sock);
close(sock);
sock := STD_NULL;
okay := FALSE;
incr(repeatCount);
end if;
end if;
until okay or repeatCount > 5;
if sock <> STD_NULL then
data := getHttp(sock);
close(sock);
end if;
end func;