1,593
社区成员
发帖
与我相关
我的任务
分享
可以使用indyhttpserver建立一个http server
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPServer, IdCustomHTTPServer,
IdHTTPServer,Comobj, StdCtrls, Buttons;
type
TForm1 = class(TForm)
IdHTTPServer1: TIdHTTPServer;
cmdPost: TBitBtn;
ListBox1: TListBox;
procedure IdHTTPServer1CommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo);
procedure FormCreate(Sender: TObject);
procedure cmdPostClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
with AThread.Connection do
begin
//
if ARequestInfo.Command = 'POST' then //解析post过来的数据
begin
listbox1.Items.Add('name is: '+ARequestInfo.Params.Values['name']);
listbox1.Items.Add('password is: '+ARequestInfo.Params.Values['password']);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
self.IdHTTPServer1.DefaultPort:=8009; //绑定http端口
self.IdHTTPServer1.Active:=true;
end;
//-----调用
procedure TForm1.cmdPostClick(Sender: TObject);
var
url:string;
xmlHttp:Olevariant;
responseText:Widestring;
begin
//发送测试数据
url:='http://127.0.0.1:8009/?name=1&password=23232ddsdsds';
try
xmlHttp:=CreateOleObject('Msxml2.XMLHTTP');
xmlHttp.open('POST',url,false);
xmlHttp.send('111111----111111');
responseText:=xmlHttp.responseText;
if xmlHttp.status='200' then
begin
//--
end
else
begin
//--
end;
except
On E:Exception do
//--
showmessage(e.Message);
end;
end;
end.