繁体   English   中英

如何使用Delphi Indy发布到HTML Form 2

[英]How to Post to HTML Form two with Delphi Indy

我想在以下HTML代码中使用Delphi XE10 Indy将其发布到Form 2(名称=“ voting_maybe”)。

<form method="post" name="voting_yes" class="dtyrd-form" action="&#x2F;vote&#x2F;yes" id="voting_yes">
<button type="submit" name="submit" class="dtyrd-button&#x20;dtyrd-button-voting&#x20;dtyrd-button-color-green" value=""><span class="image"></span>Yes</button>
</form>

<form method="post" name="voting_maybe" class="dtyrd-form" action="&#x2F;vote&#x2F;maybe" id="voting_maybe">
<input type="submit" name="submit" class="dtyrd-button&#x20;dtyrd-button-voting&#x20;dtyrd-button-color-grey" value="Maybe"> 
</form>

<form method="post" name="voting_no" class="dtyrd-form" action="&#x2F;vote&#x2F;no" id="voting_no">
<input type="submit" name="submit" class="dtyrd-button&#x20;dtyrd-button-voting&#x20;dtyrd-button-color-red" value="No">
</form>  

我想这样做:

PostStream := TIdMultiPartFormDataStream.Create;
try
  PostStream.AddFormField('submit','submit');

  Response := HTTPClient.Post(url, PostStream);

finally
  PostStream.Free;
end;

但是,如何将帖子发送到表格2(name =“ voting_maybe”)?

只需在TStringList填充name=value字符串即可,这些字符串是由voting_maybe网络表单的<input>字段定义的,然后将Post() voting_maybe该网络表单的action属性指定的URL。 每个<form>元素都应独立于同一页面上的任何其他<form>进行发布。

在这种情况下,请勿使用TIdMultiPartFormDataStream ,因为您的<form>元素上没有enctype="multipart/form-data"属性。 如果没有显式的enctype ,则默认值为application/x-www-form-urlencoded ,这是Post()TStrings版本使用的。

例如:

PostData := TStringList.Create;
try
  PostData.Add('submit=Maybe');
  Response := HTTPClient.Post(baseurl+'/vote/maybe', PostData);
finally
  PostData.Free;
end;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM