首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ServiceM8中向作业“提交文件附件”?

如何在ServiceM8中向作业“提交文件附件”?
EN

Stack Overflow用户
提问于 2016-07-22 12:06:04
回答 1查看 42关注 0票数 0

因此,我遵循了在ServiceM8中将http://developer.servicem8.com/docs/how-to-guides/attaching-files-to-a-job-diary/添加到工作日记中的步骤。我有点迷惑为什么最后一步不起作用。我已经将附件添加到作业中,并在标题中返回了UUID。我已经提取了那个UUI,然后使用curl和下面的代码;

代码语言:javascript
复制
$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”作为响应--你知道我做错了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-25 13:08:46

看起来你实际上并没有张贴任何文件内容,即你的请求试图附加一个空文件。

假设你的PDF存储在/tmp/cool_document.pdf

代码语言:javascript
复制
$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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38517978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档