uses WinINet, Windows, Sysutils, Classes, IDURI;
procedure Post(url, data:string;res:TStream);
var
hInt,hConn,hreq:HINTERNET;
buffer:PChar;
dwRead, dwFlags:cardinal;
port: Word;
uri: TIdURI;
proto, host, path: string;
begin
uri := TIdURI.Create(url);
host := uri.Host;
path := uri.Path + uri.Document;
proto := uri.Protocol;
uri.Free;
if UpperCase(proto) = "HTTPS" then
port := INTERNET_DEFAULT_HTTPS_PORT;
dwFlags := INTERNET_FLAG_SECURE;
end
else
port := INTERNET_INVALID_PORT_NUMBER;
dwFlags := INTERNET_FLAG_RELOAD;
end;
hInt := InternetOpen("Delphi",INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
hConn := InternetConnect(hInt,PChar(host),port,nil,nil,INTERNET_SERVICE_HTTP,0,0);
hreq := HttpOpenRequest(hConn,"POST",PChar(Path),"HTTP/1.1",nil,nil,dwFlags,0);
GetMem(buffer, 65536);
if HttpSendRequest(hReq,nil,0,PChar(data),Length(data)) then
dwRead:=0;
repeat
InternetReadFile(hreq,buffer,65536,dwRead);
if dwRead0 then
res.Write(buffer^, dwRead);
until dwRead=0;
InternetCloseHandle(hreq);
InternetCloseHandle(hConn);
InternetCloseHandle(hInt);
FreeMem(buffer);
uses WinINet, Windows, Sysutils, Classes, IDURI;
procedure Post(url, data:string;res:TStream);
var
hInt,hConn,hreq:HINTERNET;
buffer:PChar;
dwRead, dwFlags:cardinal;
port: Word;
uri: TIdURI;
proto, host, path: string;
begin
uri := TIdURI.Create(url);
host := uri.Host;
path := uri.Path + uri.Document;
proto := uri.Protocol;
uri.Free;
if UpperCase(proto) = "HTTPS" then
begin
port := INTERNET_DEFAULT_HTTPS_PORT;
dwFlags := INTERNET_FLAG_SECURE;
end
else
begin
port := INTERNET_INVALID_PORT_NUMBER;
dwFlags := INTERNET_FLAG_RELOAD;
end;
hInt := InternetOpen("Delphi",INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
hConn := InternetConnect(hInt,PChar(host),port,nil,nil,INTERNET_SERVICE_HTTP,0,0);
hreq := HttpOpenRequest(hConn,"POST",PChar(Path),"HTTP/1.1",nil,nil,dwFlags,0);
GetMem(buffer, 65536);
if HttpSendRequest(hReq,nil,0,PChar(data),Length(data)) then
begin
dwRead:=0;
repeat
InternetReadFile(hreq,buffer,65536,dwRead);
if dwRead0 then
res.Write(buffer^, dwRead);
until dwRead=0;
end;
InternetCloseHandle(hreq);
InternetCloseHandle(hConn);
InternetCloseHandle(hInt);
FreeMem(buffer);
end;