2

我有简单的 php 脚本。

$url = 'http://test.com/api/images/products/33';
$image_path = '/srv/images/some.jpg';
$key = 'qwerty';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_PUT, true); // Un-commet to edit an image
curl_setopt($ch, CURLOPT_USERPWD, $key.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

该脚本运行良好。我想将此代码转换为简单的 curl shell 命令。

我试过了

curl -v -X POST -d image=@/srv/images/some.jpg \
 http://qwerty@test.com/api/images/products/33

但发生错误。怎么了?

4

1 回答 1

0

您应该使用-F(for multipart/form-data) 而不是-d(which uses application/x-www-form-urlencoded):

所以这应该工作:

    curl -v -X POST -F image=@/srv/images/some.jpg http://qwerty@test.com/api/images/products/33
于 2014-07-04T12:29:10.730 回答