TMD45'β'LOG!!!

Life is Beta-ful.

curl コマンドで POST

2種類ある。それぞれ使い方と Content-Type (enctype) が異なる。
cf. enctype について http://www.tagindex.com/html5/form/form_enctype.html

あと、クエリに & を含む場合は URL をクオートで囲う必要がある。

URLエンコードして送信(一般的なデータ形式

-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 button.

$ curl -d 'a=1' -d 'b=2' http://example.com/form
# Content-Type: application/x-www-form-urlencoded

マルチパート形式で送信(ファイル送信など)

-F, --form <name=content> (HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC 2388. This enables uploading of binary files etc.

$ curl -F 'file=@"localfile",filename="nameinpost"' http://example.com/form
# Content-Type: multipart/form-data

おまけ: SSL/SSH key の指定

--key <key> (SSL/SSH) Private key file name.

$ curl --key ~/.ssh/hoge.key 'https://example.com/form?a=1&b=2'
# こんな感じ

▲ ページトップへ移動