例如如下form:
<form method="POST" action="junk.cgi">
<input type=text name="birthyear">
<input type=submit name=press value=" OK ">
</form>
curl --data "birthyear=1905&press=%20OK%20" http://www.example.com/when.cgi
你发送给服务器端的数据必须是已经被准确地编码了。curl不会自动帮你做此事。例如:如果你想使用包含了空格的数据,你需要使用%20来替换空格等。错误的请求将很可能造成你发送的数据错误,并出现混乱。新版本的curl能够执行URL编码的POST数据,比如:
# curl --data-urlencode "name=I am Daniel" http://www.example.com
<form method="POST" enctype='multipart/form-data' action="upload.cgi">
<input type=file name=upload>
<input type=submit name=press value="OK">
</form> 上面代码清楚地描述了将要发送内容的Content‐Type是multipart/form‐data。 POST一个表单,如果使用CURL,则你只需要键入下面的命令:
# curl --form upload=@localfilename --form press=OK [URL]
本文介绍了如何使用curl工具向服务器发送不同类型的表单数据,包括普通文本数据、URL编码的POST数据及multipart/form-data类型的数据。对于含有特殊字符如空格的数据,需要进行正确的编码处理。
6440

被折叠的 条评论
为什么被折叠?



