Help us understand the problem. What is going on with this article?

curlコマンドから HTTP POST する方法

More than 1 year has passed since last update.

普通のname/valueペアをPOSTする

curl -F "name1=value1" -F "name2=value2" http://yourdomain/execute.script

これが

<form method="POST" action="http://yourdomain/execute.script">
<input type="hidden" name="name1" value="value1">
<input type="hidden" name="name2" value="value2">
<input type="submit" value="submit">
</form>

みたいな感じになります。

普通のname/valueペアに加えてファイルをPOSTする

curl -F "name1=value1" -F "name2=value2" -F "profile_icon=@path/to/file.png" -F "zip_file=@path/to/zipfile.zip" http://yourdomain/execute.script

これが

<form method="POST" action="http://yourdomain/execute.script" enctype="multipart/form-data">
<input type="hidden" name="name1" value="value1">
<input type="hidden" name="name2" value="value2">
<input type="file" name="profile_icon">
<input type="file" name="zip_file">
<input type="submit" value="submit">
</form>

みたいな感じになります。

みたいな感じとは?

multipart/form-dataなど、フォーム送信する際の方式がいくつかあり、厳密に同じか確認していません。
しかも、データを受け取って保存するところまで確認していません!がきっと大丈夫。と思いたい。

TIPS

ファイル送信時、受け取り側のphpでvar_dump($_FILES);のみを出力し、

curl -F "name1=value1" -F "name2=value2" http://yourdomain/execute.script > path/to/public/web/directory/result.html

などと指定しておくと、curlの結果がわかりやすかったです。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした