curl的GET和POST使用

2023/3/11 curl

原文 curl POST examples - gists · GitHub (opens new window)

# POST application/x-www-form-urlencoded

# application/x-www-form-urlencoded is the default:
curl -d "param1=value1&param2=value2" -X POST http://localhost:3000/data

# explicit:
curl -d "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:3000/data

# with a data file
curl -d "@data.txt" -X POST http://localhost:3000/data
1
2
3
4
5
6
7
8

# POST application/json

curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data

# with a data file
curl -d "@data.json" -X POST http://localhost:3000/data
1
2
3
4

# GET with JSON

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://hostname/resource
1

# GET with XML

curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://hostname/resource
1