Code:
httpSession := InternetOpenA( PAnsiChar( tWAAgent ), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0 );
if Assigned( httpSession ) then
begin
try
httpConnect := InternetConnectA( httpSession, PAnsiChar( FServerName ), FServerHTTPPort, nil, nil, INTERNET_SERVICE_HTTP, 0, 0 ); // Check handle
if Assigned( httpConnect ) then
begin
try
httpRequest := HttpOpenRequestA( httpConnect, PAnsiChar( FServerActie ), PAnsiChar(FServerScript), nil, nil, nil,
INTERNET_FLAG_PRAGMA_NOCACHE or INTERNET_FLAG_RELOAD or INTERNET_FLAG_NO_CACHE_WRITE, 0 );
if Assigned(httpRequest) then
begin
try
if LongTimeout and (SyncTimeout <> 0) then
begin
ToSize:=SizeOf(dwFlags);
toData:=SyncTimeout * 1000 ; // moet in milliseconds; SyncTimeout is seconden
dwFlags := INTERNET_OPTION_RECEIVE_TIMEOUT or INTERNET_OPTION_CONNECT_TIMEOUT ;
if not (InternetSetOption(httpRequest, dwFlags, @toData, ToSize)) then
begin
dwError:=GetLastError;
FStatus := iWA_SETOPTERR ;
FStatusTEkst := format (tWA_SETOPTERR, [IntToStr(dwError)]);
end;
end;
if FStatus = iWA_Succes then
begin
dwSize:=SizeOf(dwFlags);
if (InternetQueryOption(httpRequest, INTERNET_OPTION_SECURITY_FLAGS, @dwFlags, dwSize)) then
begin
dwFlags:=dwFlags or SECURITY_FLAG_IGNORE_UNKNOWN_CA or SECURITY_FLAG_IGNORE_CERT_CN_INVALID or SECURITY_FLAG_IGNORE_CERT_DATE_INVALID;
if not(InternetSetOption(httpRequest, INTERNET_OPTION_SECURITY_FLAGS, @dwFlags, dwSize)) then
begin
dwError:=GetLastError;
FStatus := iWA_SETOPTERR ;
FStatusTEkst := format (tWA_SETOPTERR, [IntToStr(dwError)]);
end;
end
else
begin
dwError:=GetLastError;
FStatus := iWA_GETOPTERR ;
FStatusTEkst := format (tWA_GETOPTERR, [IntToStr(dwError)]);
end;
end;
if FStatus = iWA_Succes then
begin
repeat
if FContentType <> '' then
reqstat := HttpSendRequestA( httpRequest, PAnsiChar( FContentType ), Length( FContentType ), PAnsiChar( Request ), Length( Request ) )
else
reqstat := HttpSendRequestA( httpRequest, nil, 0, PAnsiChar( Request ), Length( Request ) ) ;
if reqStat then
dwError := ERROR_SUCCESS
else
dwError := getLastError;
buflen := length(infobuffer) ;
if HttpQueryInfo(httpRequest,HTTP_QUERY_STATUS_CODE,
@infoBuffer[0],bufLen,dummy) then
begin
FReqStatus := ansileftStr(infoBuffer,buflen);
Nu maakt het verschil welke poort gebruikt is. Van oorsprong was dat 80. FReqStatus is dan '200'. Als echter gebruik gemaakt wordt van een beveiligde verbinding (normaliter poort 443 maar met elke poort waarachter een beveiligde service hangt) is da t '4294967295' - dat is MAXUINT(0xFFFFFFFF) ofwel, als integer, -1. De rest van de 512 bytes (Buflen) is #00....
Bookmarks