0

有没有人有关于如何使用仅具有本机 Delphi 2010 功能的 Delphi 执行 Web POST 的纯 delphi 片段?

4

1 回答 1

1
const chunksize = 512;                                 //<--neu

procedure TForm1.Button1Click(Sender: TObject);
var
content,data : string;

accept :  string;
buffer :Pchar;
hSession,hConnect,hRequest : HINTERNET;
bytesread:cardinal;                                           //<--edit
name,passwort :string;
begin
  GetMem(buffer, chunksize);                             //<--neu
  Name:= 'Loginname';
  Passwort :='Passwort';
  content := 'Content-Type: application/x-www-form-urlencoded';
  data := 'v=2&universe=uni34.ogame.de&login='+Name+'&pass='+Passwort+'&button.x=22&button.y=5';
  accept :='*/*';
  hSession := InternetOpen('MyAgent',INTERNET_OPEN_TYPE_PRECONFIG,nil, nil,0);
  hConnect := InternetConnect(hSession,'uni34.ogame.de',                           //<--edit
                              80,nil,nil,INTERNET_SERVICE_HTTP, 0, 1);
  hRequest := HttpOpenRequest(hconnect,
  'POST',
  'game/reg/login2.php',
  nil,
  nil,
  plpstr(accept),
  0,1);



  httpSendrequest(hRequest,pchar(content),length(content),pchar(data),length(data));

  //-->neu+edit<--//
  memo1.lines.clear;
  repeat
    FillMemory(buffer,chunksize,0); //0 wegen null-terminiertem string
    InternetReadFile(hRequest,
    buffer,
    chunksize-1,
    bytesread);
    memo1.Lines.Text:=memo1.lines.text+Trim(string(buffer));
  until bytesread = 0;

  FreeMem(buffer);
  //-->bis hier<--//
end;

来源: http ://www.delphigl.com/forum/viewtopic.php?t=8198

于 2013-06-13T09:16:24.347 回答