[英]Rest API reqeust from jira using Vue Js and Query
I have been trying to use the JIRA rest API using vue js application, after generating the API key I have used postman to run a API request and it work perfectly. 我一直在尝试通过vue js应用程序使用JIRA rest API,在生成API密钥后,我已经使用邮递员来运行API请求,并且它运行良好。
First I have tried using the axios client but then I was stuck with cross origin because the request is 'Option' and not 'Get'. 首先,我尝试使用axios客户端,但是由于请求是“选项”而不是“获取”,因此我陷入了交叉源的困境。
That was the code: 那是代码:
axios.get(session_url, {
headers: {'Authorization': + basicAuth }
}).then(function(response) {
console.log('Authenticated');
}).catch(function(error) {
console.log('Error on Authentication');
});
Then I wanted to try a different solution and installed jquery. 然后,我想尝试其他解决方案并安装了jquery。 used this code:
使用此代码:
$.ajax({
url: session_url,
async: true,
type:'GET',
dataType: 'json',
contentType: 'application/json',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic "+btoa(auth));
},
success: function(json){
alert('success');
},
error: function(err) {
console.log(err);
}
});
But this also didn't work, I found out when using data type: 'json' the request is OPTION and then get's cross origin problem . 但这也没有用,我发现在使用数据类型:'json'时,请求为OPTION,然后得到跨源问题。 and when I'm using 'jsonp' the request gets a 400 response, when I'm looking over the request I don't see authentication request so I can edit the request and run it again and it's working.
当我使用'jsonp'时,该请求得到400响应,当我查看该请求时,没有看到身份验证请求,因此可以编辑该请求并再次运行它,并且该请求可以正常工作。
What I am doing wrong ? 我做错了什么? how can I fix that?
我该如何解决?
It's a serverside problem and not a vue-js/clientside problem: 这是服务器端问题,而不是vue-js /客户端问题:
the cross-origin error means that your vue-application runs at a different domain than your jira webserver (eg example.org and jira.com). 跨域错误意味着您的vue应用程序在与jira Web服务器不同的域上运行(例如example.org和jira.com)。 In the jira-webserver you have to set "cross-origin: *"
在jira-webserver中,您必须设置“跨域:*”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.