How to do a PUT request with curl?

2019-01-12 17:10发布

How do I test a RESTful PUT (or DELETE) method using curl?

标签: rest http curl
4条回答
时光不老,我们不散
2楼-- · 2019-01-12 17:37

Using the -X flag with whatever HTTP verb you want:

curl -X PUT -d arg=val -d arg2=val2 localhost:8080

This example also uses the -d flag to provide arguments with your PUT request.

查看更多
3楼-- · 2019-01-12 17:37

You can use the POSTMAN app from Chrome Store.

In a single line, the curl command would be:

a) If sending form data:

curl -X PUT -H "Content-Type: multipart/form-data;" -F "key1=val1" "YOUR_URI"

b) If sending raw data as json:

curl -X PUT -H "Content-Type: application/json" -d '{"key1":"value"}' "YOUR_URI"

c) If sending a file with a POST request:

curl -X POST "YOUR_URI" -F 'file=@/file-path.csv'

For the request with other formats or for different clients like java, PHP, you can check out POSTMAN/comment below.

POSTMAN to get the request code

查看更多
迷人小祖宗
4楼-- · 2019-01-12 17:42

An example PUT following Martin C. Martin's comment:

curl -T filename.txt http://www.example.com/dir/

With -T (same as --upload-file) curl will use PUT for HTTP.

查看更多
迷人小祖宗
5楼-- · 2019-01-12 17:54
curl -X PUT -d 'new_value' URL_PATH/key

where,

X - option to be used for request command

d - option to be used in order to put data on remote url

URL_PATH - remote url

new_value - value which we want to put to the server's key

查看更多
登录 后发表回答