因此,我遵循了在ServiceM8中将http://developer.servicem8.com/docs/how-to-guides/attaching-files-to-a-job-diary/添加到工作日记中的步骤。我有点迷惑为什么最后一步不起作用。我已经将附件添加到作业中,并在标题中返回了UUID。我已经提取了那个UUI,然后使用curl和下面的代码;
$service_url="https://api.servicem8.com/api_1.0/Attachment/9640887b-df46-4bfb-a47c-4afb20ed3d6b.file";
$curl = curl_init();
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_USERPWD, "user@domain.com:p@55w0rd");
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$curl_response = curl_exec($curl);我得到了一个“BAD_REQUEST /1.1400HTTP Content-Length: 0 Connection: Close”作为响应--你知道我做错了什么吗?
发布于 2016-07-25 13:08:46
看起来你实际上并没有张贴任何文件内容,即你的请求试图附加一个空文件。
假设你的PDF存储在/tmp/cool_document.pdf中
$service_url="https://api.servicem8.com/api_1.0/Attachment/9640887b-df46-4bfb-a47c-4afb20ed3d6b.file";
$file_data = file_get_contents("/tmp/cool_document.pdf"); // read the file contents from disk
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_USERPWD, "user@domain.com:p@55w0rd");
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true); // This configures CURL to send a HTTP POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $file_data); // This puts your PDF file in the body of the HTTP request
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$curl_response = curl_exec($curl);https://stackoverflow.com/questions/38517978
复制相似问题