我试图在图片网址的multipart / form-data中发送请求,但是当我尝试使用@来转换i时,得到0作为响应。请帮我解决这个问题
$img='http://mai.com/images/DC/Avanti.png';
$imagedata = array(
"name"=>'@'.$img,
"image_collection_id"=>$fid
);
$headers2= array('Accept: application/json','Content-Disposition: form-data','Referer: https://pro.avio.com/advert','Origin: https://pro.avio.com','Content-Type: multipart/form-data',"Authorization: Bearer " . $access_token,'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36');
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch2, CURLOPT_URL, 'https://api-pro.avio.com/api/image');
curl_setopt($ch2, CURLOPT_POST, true);
curl_setopt($ch2, CURLOPT_HEADER, true);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch2, CURLINFO_HEADER_OUT, true);//
curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers2);
curl_setopt($ch2, CURLOPT_POSTFIELDS,$imagedata);
$response2 = curl_exec($ch2);
$err = curl_error($ch2);
$resultStatus = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
curl_close($ch2);
echo $resultStatus;
开发人员提供的样本请求是
"request": {
"method": "POST",
"url": "https://api-pro.avio.com/api/image",
"httpVersion": "unknown",
"headers": [
{
"name": "Accept",
"value": "application/json"
},
{
"name": "Referer",
"value": "https://pro.avio.com/advert"
},
{
"name": "Origin",
"value": "https://pro.avio.com"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
},
{
"name": "Authorization",
"value": "Bearer xxxxxx"
},
{
"name": "Content-Type",
"value": "multipart/form-data; boundary=----WebKitFormBoundaryq3A6Lz2bINdfNick"
}
],
"queryString": [],
"cookies": [],
"headersSize": -1,
"bodySize": 295,
"postData": {
"mimeType": "multipart/form-data; boundary=----WebKitFormBoundaryq3A6Lz2bINdfNick",
"text": "------WebKitFormBoundaryq3A6Lz2bINdfNick\r\nContent-Disposition: form-data; name=\"name\"; filename=\"shippable.png\"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundaryq3A6Lz2bINdfNick\r\nContent-Disposition: form-data; name=\"image_collection_id\"\r\n\r\n175\r\n------WebKitFormBoundaryq3A6Lz2bINdfNick--\r\n"
}
}