我正在尝试使用POST将图像文件上传到RESTful API,没有html表单,而且我遇到了一些问题。
$data_string = "@../upload_files/images/".$data.";type=image/png";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CERTINFO, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$http_headers = array(
'Content-Type: image/png'
);
if (isset($_SESSION['Auth']))
$http_headers[] = 'Authorization: Bearer '.$_SESSION['Auth'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
这是返回HTTP代码415,并且$ info中定义的内容类型为null,即使我已定义它。有没有我在这里缺少的东西,或者是不可能将图像发布到未通过html表单上传的服务器上?