Based on some SO question I saw earlier, I'm using WinHttpRequest
inside of Inno Setup to make a GET
request to a web server (localhost:8000
right now). Minimal code below, the request is to the built-in Django debug server (python manage.py runserver
).
procedure InitializeWizard();
var
WinHttpReq: Variant;
url: string;
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER: integer;
begin
url := 'http://localhost:8000/odbc/test/';
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER := 0;
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
WinHttpReq.Open('GET', url, false);
WinHttpReq.SetRequestHeader('Accept','application/json');
WinHttpReq.SetCredentials('username','password',HTTPREQUEST_SETCREDENTIALS_FOR_SERVER);
WinHttpReq.Send();
MsgBox(WinHttpReq.Status, mbInformation, MB_OK);
MsgBox(WinHttpReq.ResponseText, mbInformation, MB_OK);
end;
This gives me a 403, authentication credentials not provided.
On the contrary, this code in the Python requests library works successfully.
>> import requests
>> r = requests.get('http://localhost:8000/odbc/test/', auth=('username','password'))
>> r.status_code
200
Am I misunderstanding how the WinHttpRequest
object works? Because Wireshark confirms an Authorization: Basic *hashstring*
header was sent in the header with the Python requests, but not in the WinHttpRequest
case. A likely workaround would be to set the header myself for the WinHttpRequest
object but I'm just curious if I'm doing anything wrong.
Gist with packet captures: https://gist.github.com/anonymous/597468ba76b59dae4a8d7809ee1c6feb
Wireshark screenshots: