用ICS控件可以搞定,下面有一段例子代码。
procedure THttpTestForm.PostButtonClick(Sender: TObject);
var
DataOut : TMemoryStream;
DataIn : TFileStream;
Buf : String;
I : Integer;
begin
DataEdit.Text:='username=' + username.Text + '&password=' + password.Text + '&realname=' + realname.Text;
DisplayMemo.Clear;
DocumentMemo.Clear;
SetButtonState(FALSE);
try
DataOut := TMemoryStream.Create;
Buf := DataEdit.Text;
if Length(Buf) > 0 then { Check if some data to post }
DataOut.Write(Buf[1], Length(Buf));
DataOut.Seek(0, soFromBeginning);
httpcli1.SendStream := DataOut;
httpcli1.Proxy := ProxyHostEdit.Text;
httpcli1.ProxyPort := ProxyPortEdit.Text;
httpcli1.RcvdStream := nil;
httpcli1.URL := URLEdit.Text;
if httpcli1.Proxy <> '' then
Display('Using proxy ''' + httpcli1.Proxy + ':' +
httpcli1.ProxyPort + '''')
else
Display('Not using proxy');
try
httpcli1.Post;
except
DataOut.Free;
Display('POST Failed !');
Display('StatusCode = ' + IntToStr(httpcli1.StatusCode));
Display('ReasonPhrase = ' + httpcli1.ReasonPhrase);
Exit;
end;
DataOut.Free;
Display('StatusCode = ' + IntToStr(httpcli1.StatusCode));
for I := 0 to httpcli1.RcvdHeader.Count - 1 do
Display('hdr>' + httpcli1.RcvdHeader.Strings);
DataIn := TFileStream.Create(httpcli1.DocName, fmOpenRead);
try
DocumentMemo.Lines.LoadFromStream(DataIn);
finally
DataIn.Free;
end;
finally
SetButtonState(TRUE);
end;
if (DocumentMemo.Lines[0]='验证成功') then
begin
lbl.Caption:='验证成功';
ShowMessage('验证成功');
end
else
begin
lbl.Caption:='验证失败';
ShowMessage('验证失败');
end;
end;