接收post过来的数据

duipi 2008-11-15 11:30:02
asp接收post过来的数据方法是:
<%
name=trim(request.form("name"))
password=trim(request.form("password"))
response.Write (name&"<br>"&password)
%>

delphi如何实现这个功能呢,
接收post过来的name和password,并showmessage显示出来
...全文
117 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
panrongzeng 2008-11-15
  • 打赏
  • 举报
回复
不清楚是什么的post
jadeluo 2008-11-15
  • 打赏
  • 举报
回复
用Delphi编写HTTP服务器?还是用Delphi写CGI?
hongqi162 2008-11-15
  • 打赏
  • 举报
回复

可以使用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.
僵哥 2008-11-15
  • 打赏
  • 举报
回复
这个不是那么容易的,建议自己去了解一下HTTP协议相关的RFC文档。
比如你可以得到HTTP请求当中的HttpData,然后根据&分解,就可以得到Name=YourName之类的信息,用StringList分解就是了。当然需要注意一些百分号(%)打头的转义字符。
duipi 2008-11-15
  • 打赏
  • 举报
回复
用Delphi编写的HTTP服务器,有人知道吗,帮助一下.
只要能接收到post过来的数据并显示就可以了,

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧