被困在这上面好几天了。我正在制作一个使用亚特兰西安的Jira Cloud的React应用程序,我想从我的应用程序中记录Jira问题的工作。然而,每次我试一次,我都会得到403分。Postman中的相同请求工作,它创建工作日志,这是奇怪的。我设置了一个证书并使用cors-任何地方都可以在我的React应用程序中使用HTTPS,但否则查询是相同的。
我在亚特兰西安的论坛上读过一堆关于人们在需要发布到亚特兰的API时不确定该做什么的条目。这是什么奇怪的东西,无法修复,还是我缺少了一个相关的标题?
下面是我在React应用程序的ComponentDidMount()中进行的提取调用。https://localhost:8080是我为CORS-anywhere/Yarn使用的代理。
fetch("https://localhost:8080/my-domain.atlassian.net/rest/api/2/issue/ISSUE-1/worklog,{
headers: {
"Access-Control-Allow-Origin": "https://localhost:3000/",
"X-Atlassian-Token": "no-check",
"Content-Type": "application/json;charset=UTF-8",
"Authorization": "Basic base64token",
},
method: "POST",
responseType: 'json',
body: {
"timeSpent":"2h 48m",
"author":{
"accountId":"123456789",
"active":true,
"avatarUrls":{
"16x16":"https://avatar-cdn.atlassian.com/...",
"24x24":"https://avatar-cdn.atlassian.com/...",
"32x32":"https://avatar-cdn.atlassian.com/...",
"48x48":"https://avatar-cdn.atlassian.com/..."
},
"displayName":"User Name",
"emailAddress":"user.name@gmail.com",
"key":"user.name",
"name":"user.name",
"self":"https://my-domain.atlassian.net/rest/api/2/user?username=user.name",
"timeZone":"Europe/Stockholm"
},
"comment":"bla bla bla",
"started":"2018-07-19T21:32:18.843+0200"
}
})
.then((res) => res.json())
.then(function(resJson){
console.log(resJson
})这是亚恩运行的server.js。
const path = require('path')
const fs = require('fs')
const express = require('express')
const https = require('https')
const app = express();
const host = process.env.HOST || '0.0.0.0';
const port = process.env.PORT || 8080;
const cors_proxy = require('cors-anywhere');
cors_proxy.createServer({
httpsOptions: {
key: fs.readFileSync(path.resolve('server.key')),
cert: fs.readFileSync(path.resolve('server.crt'))
},
originWhitelist: ['https://localhost:3000', 'https://localhost:8080'],
requireHeader: ['origin', 'x-requested-with'],
removeHeaders: ['cookie', 'cookie2']
}).listen(port, host, function() {
console.log('Running CORS Anywhere on ' + host + ':' + port);
});https://stackoverflow.com/questions/51450092
复制相似问题