How to do a PUT request with curl?

前端 未结 5 1602
难免孤独
难免孤独 2020-12-02 04:18

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

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 05:11

    I am late to this thread, but I too had a similar requirement. Since my script was constructing the request for curl dynamically, I wanted a similar structure of the command across GET, POST and PUT.

    Here is what works for me

    For PUT request:

    curl --request PUT --url http://localhost:8080/put --header 'content-type: application/x-www-form-urlencoded' --data 'bar=baz&foo=foo1'
    

    For POST request:

    curl --request POST --url http://localhost:8080/post --header 'content-type: application/x-www-form-urlencoded' --data 'bar=baz&foo=foo1'
    

    For GET request:

    curl --request GET --url 'http://localhost:8080/get?foo=bar&foz=baz'
    

提交回复
热议问题