Main problems:
The second InternetConnect parameter should contain only the server name, and not the entire server side URL of the script.
The third parameter of HttpOpenRequest should be the name of the script file, and not the POST data!
The actual POST data should be the fourth parameter of the HttpSendRequest .
Minor issues
Code example
I use the following code for POST data:
procedure WebPostData(const UserAgent: string; const Server: string; const Resource: string; const Data: AnsiString); overload; var hInet: HINTERNET; hHTTP: HINTERNET; hReq: HINTERNET; const accept: packed array[0..1] of LPWSTR = (PChar('*/*'), nil); header: string = 'Content-Type: application/x-www-form-urlencoded'; begin hInet := InternetOpen(PChar(UserAgent), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); try hHTTP := InternetConnect(hInet, PChar(Server), INTERNET_DEFAULT_HTTP_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 1); try hReq := HttpOpenRequest(hHTTP, PChar('POST'), PChar(Resource), nil, nil, @accept, 0, 1); try if not HttpSendRequest(hReq, PChar(header), length(header), PChar(Data), length(Data)) then raise Exception.Create('HttpOpenRequest failed. ' + SysErrorMessage(GetLastError)); finally InternetCloseHandle(hReq); end; finally InternetCloseHandle(hHTTP); end; finally InternetCloseHandle(hInet); end; end;
For instance:
WebPostData('My UserAgent', 'www.rejbrand.se', 'mydir/myscript.asp', 'value=5');
Update in response to OP response
To read data from the Internet, use the InternetReadFile function. I use the following code to read a small (single line) text file from the Internet:
function WebGetData(const UserAgent: string; const Server: string; const Resource: string): string; var hInet: HINTERNET; hURL: HINTERNET; Buffer: array[0..1023] of AnsiChar; i, BufferLen: cardinal; begin result := ''; hInet := InternetOpen(PChar(UserAgent), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); try hURL := InternetOpenUrl(hInet, PChar('http://' + Server + Resource), nil, 0, 0, 0); try repeat InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen); if BufferLen = SizeOf(Buffer) then result := result + AnsiString(Buffer) else if BufferLen > 0 then for i := 0 to BufferLen - 1 do result := result + Buffer[i]; until BufferLen = 0; finally InternetCloseHandle(hURL); end; finally InternetCloseHandle(hInet); end; end;
Sample Usage:
WebGetData('My UserAgent', 'www.rejbrand.se', '/MyDir/update/ver.txt')
This function, therefore, only reads data without a preliminary POST. However, the InternetReadFile function can also be used with a descriptor created by HttpOpenRequest , so it will work in your case HttpOpenRequest . You know that the WinInet link is MSDN, right? All functions of the Windows API are described in detail there, for example InternetReadFile .