回覆列表
  • 1 # 我是阿嘛

    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;

  • 中秋節和大豐收的關聯?
  • 陳情陳語之不忘是什麼歌?