I was trying out this function to perform a GET request using Delphi and the WinIApi. The request itself works, but unforunately the response is encoded wrong. I haven't fully worked out how it is encoded, but when it returns
≻牯杩湩㨢㤢⸳㤱⸸ㄲ⸹㤵索
and I throw it into an online encoder it returns the following using utf-16 and utf-32 encoding:
"{rogini:"9".391.812.995}"
So it's almost what it's supposed to be, but it flips two chars around everywhere:
{"origin":"93.198.219.59"}
So the question is how to correctly encode this without using Indy components.
EDIT: I used the function from here:
uses WinInet;
function GetUrlContent(const Url: string): string;
var
NetHandle: HINTERNET;
UrlHandle: HINTERNET;
Buffer: array[0..1024] of Char;
BytesRead: dWord;
begin
Result := '';
NetHandle := InternetOpen('Delphi 5.x', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(NetHandle) then
begin
UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);
if Assigned(UrlHandle) then
{ UrlHandle valid? Proceed with download }
begin
FillChar(Buffer, SizeOf(Buffer), 0);
repeat
Result := Result + Buffer;
FillChar(Buffer, SizeOf(Buffer), 0);
InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
until BytesRead = 0;
InternetCloseHandle(UrlHandle);
end
else
{ UrlHandle is not valid. Raise an exception. }
raise Exception.CreateFmt('Cannot open URL %s', [Url]);
InternetCloseHandle(NetHandle);
end
else
{ NetHandle is not valid. Raise an exception }
raise Exception.Create('Unable to initialize Wininet');
end;