繁体   English   中英

使用PHP cUrl将文件上传到JIRA REST API

[英]Upload file to JIRA REST API with PHP cUrl

我想使用REST API将文件上传到JIRA。

我的代码:

$ch_api = curl_init('https://website.com/rest/api/2/issue/SI-10255/attachments');

curl_setopt($ch_api, CURLOPT_POST, true);
curl_setopt($ch_api, CURLOPT_POSTFIELDS, json_encode(["file" => "@t.txt"]));
curl_setopt($ch_api, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data','X-Atlassian-Token:no-check'));

curl_setopt($ch, CURLOPT_USERPWD, "login:password");
curl_setopt($ch_api, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch_api);
curl_close($ch_api);

而且我有这个错误:

the request was rejected because no multipart boundary was found

当我添加边界时,文件不会上传。 api的响应为空数组。

请帮忙。

谢谢。

要将文件上传到JIRA REST API,请不要使用标题“ Content-Type:multipart / form-data”

对于文件,请使用以下代码:

if (function_exists('curl_file_create')) {
        $cFile = curl_file_create("file.txt");
    } else { 
        $cFile = '@' . realpath("file.txt");
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM