You are not logged in.
Hi,
I'm trying to use an inherited TWinHttp (from THttpRequest) to download the content from an URL.
It *seems* to work... except that the result is not what's expected ! The content is retrieved (status code = 200), but is different from the (expected) one I get when using the HttpGet (from SynCtrlSock too) !?
Sample ex.:
- With WinHttp...
function blabla.GetContent1: SockString;
var
Http: {$IFDEF MSWINDOWS}TWinHTTP{$ELSE}TCurlHTTP{$ENDIF};
sInHeaders, sInData, sOutHeaders: SockString;
sUrl: string;
iResponseStatus: Integer;
begin
Result := '';
sUrl := 'https://www.betexplorer.com/soccer/';
Http := {$IFDEF MSWINDOWS}TWinHTTP{$ELSE}TCurlHTTP{$ENDIF}.Create(Url);
try
iResponseStatus := Http.Request(sUrl, 'GET', 0, sInHeaders, sInData, '', sOutHeaders, Result);
finally
Http.Free;
end;
end;
- With HttpGet
function blabla.GetContent2: SockString;
var
sUrl: string;
begin
sUrl := 'https://www.betexplorer.com/soccer/';
Result := HttpGet(sUrl);
end;
So, the URL is specific, it may work in a different way on other URLs but that's the one I need to get. On the first case the content seems to be from the "main" page, while the second comes from the requested page ("soccer" page).
Did I miss some parameter when using TWinHttp ? Is something happening on the external server that detects the origin from the request to send it a different content ? I can't understand what's happening between the two cases :-\
Thanks.
Offline
It's a little confusing in first parameter name of Request method - it expect a path, not a full URL. So first example should be:
sUrl := 'https://www.betexplorer.com'; sPath = '/soccer/'
Http := {$IFDEF MSWINDOWS}TWinHTTP{$ELSE}TCurlHTTP{$ENDIF}.Create(sUrl);
try
iResponseStatus := Http.Request(sPath, 'GET', 0, sInHeaders, sInData, '', sOutHeaders, Result);
finally
Http.Free;
end;
Inside HttpGet source you can see how to parce URL onto parts using URI.from(URL)
Offline
@mpv, how to disable urlencode of sPath?
thanks!
Offline
Ooooh ! Thanks again @mpv !
(BTW I already said that somewhere on this forum, but we really need a "thumbs up" button ! No obvious way to thankfully mention the great help and the incredible work of ab :-p)
Offline