You are not logged in.
Hi,
Sorry, I'm going back to Delphi after a quite long break and I lost some obvious knowledge :-\ (and I crashed a few months ago, spent a couple of weeks in coma, it seems that some things are now damaged in my brain now... not complaining, just using this as an argument to get mercy for an answer :-p)
So, I'm trying to use TWinHttp to download the content of some web pages, the class is working as expected but I'd like 1- to have more control on the User-Agent ("myClass(TWinHttp).UserAgent := 'blabla'" should be OK, right ?) and 2- to retrieve the status code from the server (200, 404, 2xx, 3xx, ...): how to do it with TWinHttp ?
Thanks !
Offline
At least for the status code, from another newbie
The status code is contained in the first line of the OutHeaders string, e.g. (XXX is the placement of the status code, DESCR is the placement of the corresponding textual description, like OK, followed by CRLF):
HTTP/1.1 XXX DESCR#13#10
The OutHeaders string is an output parameter both in HttpGet and in TWinHTTP.Post:
var
sOutHeaders, sResponse, sURL, sData, sHeaders: SockString;
...
sResponse := HttpGet(sURL, sHeaders, @sOutHeaders);
...
sResponse := TWinHTTP.Post(sURL, sData, sHeaders, true, @sOutHeaders);
Offline
You do not need to parse headers manually. Just use a low level call.
This is cross platform solution:
var fClient: THttpRequest;
fClient := {$IFDEF MSWINDOWS}TWinHTTP{$ELSE}TCurlHTTP{$ENDIF}
.Create(aServer, aPort, aHttps, aProxyName, aProxyByPass, fConnectTimeout, fSendTimeout, fReceiveTimeout);
try
FResponseStatus := fClient.Request(URL, FMethod, keepAlive, fInHeaders, FInData, '', FRespHeaders, FRespText);
except
on E: EOSError do
FResponseStatus := E.ErrorCode;
end;
Offline
Thanks @damiand and @mpv for your help ! :-)
Offline