我有这个帖子请求给JIRA创建一个问题:
require('isomorphic-fetch');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var summ = "Review Test Ticket";
var issue = {
"fields": {
"project":
{
"key": "ABC"
},
"summary": summ,
"description": "This is a test JIRA issue creation",
"issuetype": {
"name": "Story"
},
"assignee": {
"name": "myname"
},
"customfield_10902": [{ "value": "Red Team" }],
"customfield_10008": 1
}
};
var missue = JSON.stringify(issue)
fetch("https://my_jira_host/jira/rest/api/2/issue/", {
body: missue,
headers: {
"Authorization": "Basic my_auth_token",
"Content-Type": "application/json"
},
method: "POST"
})
.then(function( data ) {
console.log(data);
}).catch(function(data) {
alert(data);
});
如果以上代码位于名为" my_file.js"的文件中。如果我运行node my_file.js
,则表单已成功创建。
但是,如果我将该代码移动到在我的react应用程序中单击按钮上运行的函数中,然后运行应用程序(在localhost或服务器上),则它将失败。我得到了403.我的捕获显示的警告是:TypeError: NetworkError when attempting to fetch resource.
我绝对尝试过一切。不知道从哪里开始。有什么想法吗?