我有简单的 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
但发生错误。怎么了?