美文网首页命令行工具
使用 cURL 测试 RESTful API

使用 cURL 测试 RESTful API

作者: 舌尖上的大胖 | 来源:发表于2017-06-11 15:18 被阅读0次

一、GET
$ curl "http://httpbin.org/get?param1=value1&param2=value"
二、POST
$ curl -d "item1=111&item2=222" "http://httpbin.org/post?param1=value1&param2=value"

--data-urlencode 可以处理参数中的特殊字符

使用数据文件:

$ curl -d @data.txt http://httpbin.org/post
三、PUT
$ curl -X PUT -d "item1=111&item2=222" "http://httpbin.org/put?param1=value1&param2=value"
四、DELETE
$ curl -X DELETE -d "item1=111&item2=222" "http://httpbin.org/delete?param1=value1&param2=value"
五、HEAD
$ curl -I "http://httpbin.org/anything"
六、Cookie

命令行传 Cookie 值:

$ curl -b "Cookie_1=value; Cookie_2=value2" "http://httpbin.org/cookies"

通过文件传 Cookie 值:

$ curl -b cookie.txt "http://httpbin.org/cookies"

cookie.txt 文件格式:

Set-Cookie:k1=v1; Path=/
Set-Cookie:k2=v2; Path=/
Set-Cookie:k3=v3; Path=/
七、上传文件
$ curl --form "fileupload=@filename.txt" http://hostname/resource
八、参考链接

(完)

相关文章

网友评论

    本文标题:使用 cURL 测试 RESTful API

    本文链接:https://www.haomeiwen.com/subject/ydvhqxtx.html