curl で post する
unix curl
Published: 2018-05-27


api を作成する機会がありました。

動作確認のためターミナルから api を実行する方法を調べました。


url パラメータを POST する

$ curl http://localhost:9000/hoge -F "url="

DELETE メソッドでアクセス

$ curl http://localhost:9000/hoge/1 -X DELETE

PUT メソッドで url パラメータを送る

$ curl http://localhost:9000/hoge/1 -X PUT -F "url="

(以下 man コマンドより引用)

       -d, --data <data>
              (HTTP)  Sends  the  specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and
              presses the submit button. This will cause curl to pass the data to the server using the content-type  application/x-www-form-urlencoded.   Compare  to
              -F, --form.
       -X, --request <command>
              (HTTP)  Specifies  a  custom  request  method to use when communicating with the HTTP server.  The specified request method will be used instead of the
              method otherwise used (which defaults to GET). Read the HTTP 1.1 specification for details and explanations. Common additional  HTTP  requests  include
              PUT and DELETE, but related technologies like WebDAV offers PROPFIND, COPY, MOVE and more.