从Angular 4项目向JIRA发出HTTP POST请求,抛出ERROR 403

时间:2017-07-28 22:36:32

标签: angular http post jira

我正在尝试使用Angular4执行HTTP POST请求以创建JIRA Issue票证。

以下是我正在使用的代码片段:

const username = 'username';
const password = 'password';
const params = '{' +
                  '"fields":{' +
                      '"project": {' +
                            '"key": "ABCD" },' +
                        '"summary": "' + this.form.value.summary + '",' +
                        '"description":"' + this.form.value.description + '",' +
                        '"issuetype": {' +
                          '"name" : "' + this.form.value.issuetype + '"},' +
                        '"customfield_10041": {"value": "' + this.form.value.storyType + '"}' +
                      '}' +
                  '}' ; 

const headers = new Headers();
headers.append('Host', 'https://jira-uat.in.here.com');
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Basic ' + btoa(username + ':' + password));

return this.http.post('https://someURI/rest/api/2/issue/', params , {headers: headers}).map(res => res.json());

虽然我能够使用POSTMAN(用于测试Web服务的HTTP客户端)成功创建JIRA问题,但是当我尝试运行我的Angular项目时,它会抛出以下错误:

 ERROR: Response with status: 403 Forbidden for URL: https://someURI/rest/api/2/issue/

关于我在这里错过了什么的任何线索?

当我尝试编译代码时,以下是传递的REQUEST HEADERS -

 Accept:application/json, text/plain, */*
 Accept-Encoding:gzip, deflate, br
 Accept-Language:en-US,en;q=0.8
 Authorization:Basic Z**********************h
 Connection:keep-alive
 Content-Length:149
 Content-Type:application/json
 Host:someURI
 Origin:http://evil.com/
 Referer:http://localhost:4200/someRoute
 User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 
 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36

以下是响应标题:

Cache-Control:no-cache, no-store, no-transform
Connection:Keep-Alive
Content-Type:text/html;charset=UTF-8
Date:Tue, 01 Aug 2017 17:35:41 GMT
Keep-Alive:timeout=5, max=99
Server:Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_jk/1.2.41
Set-Cookie:JIRA72ARD1SESSIONID=E558106054FA151216527F0A66C6D204; Path=/; Secure; HttpOnly
Set-Cookie:atlassian.xsrf.token=BO4R-SWLP-WXR5-89O4|b25695ca2bee6fbaa48e9cddcf023d851bfc5bf5|lin; Path=/; Secure
Transfer-Encoding:chunked
X-AREQUESTID:1055x68000x1
X-ASEN:SEN-2026451
X-ASESSIONID:c993lp
X-AUSERNAME:username
X-Content-Type-Options:nosniff
X-Seraph-LoginReason:OK

不确定导致问题的是什么错误!

0 个答案:

没有答案