curl 命令使用

curl命令使用。

基础知识

-v:可输出调试信息。

GET操作

1
2
3
4
5
6
7
8
curl localhost:8080/test

curl http://127.0.0.1:4000/

curl https://jsonplaceholder.typicode.com/posts

curl https://jsonplaceholder.typicode.com/posts?userId=1

POST操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
curl localhost:8080/test -X POST -d "title=hello&name=latelee"
curl http://127.0.0.1:4000/set -X POST -H "Content-Type:application/json" -d '{"cmd":"set","content":"foobar"}'

curl http://127.0.0.1:8090/api/user/login -X POST -H "Content-Type:application/json" -d '{"userName":"admin","passWord":"foobar"}'

curl -X POST -d "userId=250&title=myfoo&body=Post body." https://jsonplaceholder.typicode.com/posts
(注:似乎不能再get,应该是即时返回数据)



curl http://127.0.0.1:4000/test -X POST -H "Content-Type:application/json" -F "file=@foo.json"
(注:不使用-H指定json也行,有些服务会自动检查文件,但建议加上)

eg:
curl http://10.145.0.40:84/fee/test -X POST -H "Content-Type:application/json" -F "file=@PSPE_EXTQ_BSTG_REQ_123.json"
curl http://10.145.0.40:84/fee/test -X POST -F "file=@PSPE_EXTQ_BSTG_REQ_123.json"

上传文件

1
2
3
4
curl localhost:8000/api/v1/upimg -F "file=@foo.json"

curl -X POST -F 'image=@/home/user/Pictures/wallpaper.jpg' http://example.com/upload

证书

1
2
指定证书 curl --cacert 路径
curl -E mycert.pem https://api.test.com/open_api