curl常用命令
--发布于 2023-02-09 12:31:37
发送json
curl 'https://example.com/test' \
-H "Content-Type:application/json" \
-X POST \
-d '{"code":200,"message":"success"}'
如果json数据在文件test.json中
curl 'https://example.com/test' \
-H "Content-Type:application/json" \
-X POST \
-d '@/test.json'
post 发送x-www-form-urlencoded数据
curl -X POST http://127.0.0.1:8442/test -H "Content-Type: application/x-www-form-urlencoded" -d "c=WebSocket&a=kick&conn_id=2"
上传文件
curl -X POST -F 'image=@/path/to/pictures/picture.jpg' http://domain.tld/upload
如果使用PHP代码打印出$_FILES变量
Array(
"image": array(
"name" => "picture.jpg"
"type" => "image/jpeg",
"tmp_name" => "/path/on/server/to/tmp/phprj5rkG",
"error" => 0,
"size" => 174476
)
)
使用curl发送multipart/form-data
curl -v -F key1=value1 -F upload=@localfilename URL
来自这里
https://stackoverflow.com/questions/53724134/use-curl-to-post-multipart-form-data-file-and-lots-of-key-value-pairs
参考
--更新于 2023-03-09 10:51:41