Welcome, guest! Login / Register - Why register?
[email protected] webmail now available. Want one? Go here.
Windows getting boring or just want to try something Open Source for your next Desktop Environment?! Go Zorin OS.

Paste

N/A
Pasted as Delphi by noxwow ( 12 years ago )
function Check(const UserAgent: string; const Server: string; const Resource: string; const Data: AnsiString): string;
var
  hInet: HINTERNET;
  hHTTP: HINTERNET;
  hReq: HINTERNET;
  Buffer: array[0..1023] of AnsiChar;
  i, BufferLen: Cardinal;
const
  accept: packed array[0..1] of LPWSTR = (PChar('*/*'), nil);
  header: string = 'Content-Type: application/x-www-form-urlencoded';
begin
  Result := '';

  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));
        repeat
          InternetReadFile(hReq, @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(hReq);
      end;
    finally
      InternetCloseHandle(hHTTP);
    end;
  finally
    InternetCloseHandle(hInet);
  end;
end;

...

Memo1.Text := Check('UserAgent', 'www.mysite.com', 'test.php', 'test=123');

 

Revise this Paste

Your Name: Code Language: