delphi获得html文本框,用Delphi捕获HTML帖子?

首先,让我先说:

if ARequestInfo.Command = 'POST' then

if TextIsSame(ARequestInfo.Command, 'POST') then

if ARequestInfo.CommandType = hcPOST then

OnCommand...

现在,您所显示的HTML将使用

application/x-www-webform-urlencoded

媒体类型将webform值发布到HTTP服务器。在

TIdHTTPServer.OnCommandGet

事件中,

ARequestInfo.PostStream

属性不与该媒体类型一起使用,而是

nil

。如果

ARequestInfo.FormParams

属性为真(默认情况下为真),则发布的webform值将以其原始未解析格式在

ARequestInfo.UnparsedParams

ARequestInfo.Params

属性中可用,并以解析格式在

TIdHTTPServer.ParseParams

属性中可用。

请改为:

procedure TForm1.serviceCommandGet(AContext: TIdContext;

ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);

var

testValue: string;

begin

if ARequestInfo.URI = '/test.php' then

begin

if ARequestInfo.CommandType = hcPOST then

begin

testValue := ARequestInfo.Params.Values['test'];

TThread.Queue(nil,

procedure

begin

LOG.Lines.Add('test: ' + testValue);

end

);

AResponseInfo.ResponseNo := 200;

end else

begin

AResponseInfo.ResponseNo := 405;

end;

end else

begin

AResponseInfo.ResponseNo := 404;

end;

end;

也就是说,测试工具中的表单数据指的是

multipart/form-data

媒体类型。在HTML中,如果要使用该媒体类型发布web表单,则必须在

enctype

元素的

参数中明确声明,例如:

在这种情况下,

TIdHTTPServer

目前不支持解析

multipart/form-data

帖子,因此

ARequestInfo.PostStream

将不会是

nil

,它提供了网络表单的原始字节,因此您可以根据需要手动解析数据。

您可以通过查看

ARequestInfo.ContentType

属性来区分用于发布Web表单的媒体类型,例如:

procedure TForm1.serviceCommandGet(AContext: TIdContext;

ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);

var

testValue: string;

data: string;

begin

if ARequestInfo.URI = '/test.php' then

begin

if ARequestInfo.CommandType = hcPOST then

begin

if IsHeaderMediaType(ARequestInfo.ContentType, 'application/x-www-form-urlencoded') then

begin

testValue := ARequestInfo.Params.Values['test'];

TThread.Queue(nil,

procedure

begin

LOG.Lines.Add('test: ' + testValue);

end

);

AResponseInfo.ResponseNo := 200;

end

else if IsHeaderMediaType(ARequestInfo.ContentType, 'multipart/form-data') then

begin

data := ReadStringFromStream(ARequestInfo.PostStream);

TThread.Queue(nil,

procedure

begin

LOG.Lines.Add('form-data: ' + testValue);

end

);

AResponseInfo.ResponseNo := 200;

end else

begin

AResponseInfo.ResponseNo := 415;

end;

end else

begin

AResponseInfo.ResponseNo := 405;

end;

end else

begin

AResponseInfo.ResponseNo := 404;

end;

end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值