[英]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="/vote/yes" id="voting_yes">
<button type="submit" name="submit" class="dtyrd-button dtyrd-button-voting dtyrd-button-color-green" value=""><span class="image"></span>Yes</button>
</form>
<form method="post" name="voting_maybe" class="dtyrd-form" action="/vote/maybe" id="voting_maybe">
<input type="submit" name="submit" class="dtyrd-button dtyrd-button-voting dtyrd-button-color-grey" value="Maybe">
</form>
<form method="post" name="voting_no" class="dtyrd-form" action="/vote/no" id="voting_no">
<input type="submit" name="submit" class="dtyrd-button dtyrd-button-voting 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.