curl表单数据_使⽤cURL发布表单数据
curl 表单数据
cURL is the magical utility that allows developers to , , , , and much more.  One more great usage of cUrl for command line
is POSTing form data to a server, especially while testing moderate to advanced form processing.  And just like other cURL commands, POSTing form data is incredibly simple.
cURL是⼀种神奇的实⽤程序,它使开发⼈员可以 , , , 等等。 命令⾏使⽤cUrl的另⼀⼤⽤途是将表单数据发布到服务器,特别是在测试中级到⾼级表单处理时。 就像其他cURL命令⼀样,POST表单数据⾮常简单。
curl命令发送post请求带参数
使⽤cURL过帐表单数据 (POSTing Form Data with cURL)
Start your cURL command with curl -X POST and then add -F for every field=value you want to add to the POST:
使⽤curl -X POST启动cURL命令,然后为要添加到POST的每个field=value添加-F :
curl -X POST -F 'username=davidwalsh' -F 'password=something' domain.tld/post-to-me.php
If you were using PHP, you could use print_r on the $_POST variable to see that your server received the POST data as expected:
如果您使⽤的是PHP,则可以在$_POST变量上使⽤print_r来查看服务器是否按预期接收到POST数据:
Array(
'username' => 'davidwalsh',
'password' => 'something'
)
If you need to send a specific data type or header with cURL, use -H to add a header:
如果需要使⽤cURL发送特定的数据类型或标头,请使⽤-H添加标头:
# -d to send raw data
curl -X POST -H 'Content-Type: application/json' -d '{"username":"davidwalsh","password":"something"}' domain.tld/login
使⽤cURL发布⽂件 (POSTing Files with cURL)
POSTing a file with cURL is slightly different in that you need to add an @ before the file location, after the field name:
使⽤cURL张贴⽂件稍有不同,因为您需要在⽂件位置之前,字段名称之后添加@ :
curl -X POST -F 'image=@/path/to/pictures/picture.jpg' domain.tld/upload
Using PHP to explore the $_FILES variable array would show file data as though it was uploaded via a form in browser:
使⽤PHP探索$_FILES变量数组将显⽰⽂件数据,就像通过浏览器中的表单上传⽂件⼀样:
Array(
"image": array(
"name" => "picture.jpg"
"type" => "image/jpeg",
"tmp_name" => "/path/on/server/to/tmp/phprj5rkG",
"error" => 0,
"size" => 174476
)
)
POSTing file contents with cURL is Probably easier than you thought, right?
使⽤cURL发布⽂件内容可能⽐您想象的要容易,对吧?
The first time I needed to POST file data from command line I thought I was in for a fight; instead I found that cURL made the process easy!
第⼀次需要从命令⾏发布⽂件数据时,我以为⾃⼰会参加战⽃。 相反,我发现cURL使该过程变得容易!
curl 表单数据

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。