Does anyone have a snippet of pure delphi on how to perform a web POST using Delphi with only native Delphi 2010 functionality?
Asked
Active
Viewed 804 times
0
-
WinInet is that a built-in Delphi module? – Stephan Møller Jun 13 '13 at 09:27
-
3Nope. It's [`part of Windows`](http://msdn.microsoft.com/en-us/library/windows/desktop/aa383630(v=vs.85).aspx). – TLama Jun 13 '13 at 09:28
1 Answers
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;

Hidden
- 3,598
- 4
- 34
- 57