1

我有以下代码尝试将附件上传到 Jira 问题:

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: multipart/form-data;'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://jira.example.com/rest/api/2/issue/JT-1/attachments');
curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// same as <input type="file" name="file_box">
$post = array(
    "file"=>"@/tmp/Screen_Shot_2012_10_18_at_2.58.33_PM.png",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$response = curl_exec($ch);

var_dump($response);
var_dump(curl_error($ch));

curl_close($ch);

但是我收到一条错误消息:

XSRF check failed

我该怎么做才能防止出现此错误?

4

1 回答 1

1

发现我需要添加标题:

X-Atlassian-Token: nocheck

应我的要求。

于 2012-10-31T18:18:13.457 回答