我很难用PHP cURL发布到API . 我觉得我已经尝试过各种组合 . 我的脚本正在连接,但问题出在有效负载内 .
根据文档,这是必需的请求 .
--85b890d4-4faf-4261-bcbb-187c4dddcbc6 Content-Type:application / vnd.emc.ax json; charset = utf-8 Content-Disposition:form-data;名称=数据
{
"Name": "batch name",
"Description": "batch description",
"Private": false
}
--85b890d4-4faf-4261-bcbb-187c4dddcbc6 Content-Type:application / bin Content-Disposition:form-data;名称=斌;文件名=“检验.pdf”; filename * = utf-8''test.pdf // bin文件内容--85b890d4-4faf-4261-bcbb-187c4dddcbc6 Content-Type:application / bin Content-Disposition:form-data;命名=注释;文件名= “0100002m.ano”; filename * = utf-8''0100002m.ano //注释文件内容--85b890d4-4faf-4261-bcbb-187c4dddcbc6 Content-Type:application / bin Content-Disposition:form-data;名称=文本;文件名= “test.txt的”; filename * = utf-8''test.txt // ocr文件内容--85b890d4-4faf-4261-bcbb-187c4dddcbc6--
这是我的代码
$file = file_get_contents("tiff/test.TIF");
$curl = curl_init();
$data = array(
'Content-Type: application/vnd.emc.ax+json; charset=utf-8 Content Disposition: form-data; name=data',
'{"Name":"Here is my Name","Description":"Testing This","Private":false}',
chunk_split(base64_encode($file))
);
curl_setopt_array($curl, array(
CURLOPT_URL =>"*********************************",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $d,
CURLOPT_HTTPHEADER => array(
"Authorization: **********************************",
"Content-Type: multipart/form-data; boundary=85b890d4-4faf-4261-bcbb-187c4dddcbc6",
),
));
curl_close($curl);
我的代码产生了这个错误:
{“ErrorCode”:9999,“Message”:“MIME多部分流的意外结束.MIME multipart消息未完成 . ”,“InnerException”:null}
有人请帮助我吗?