0

我正在尝试使用来自独立 OpenSocial (Atlassian Jira) 小工具的以下 REST 资源。

我可以使用以下 URL 通过浏览器查询资源:

https://jira.atlassian.com/rest/api/latest/issue/JRA-9

我可以从我的开发机器发出相同的请求。对我来说,它当然看起来像 JSON ......但是,当我从我的小工具查询时,我得到

GET 10.0.15.10:2990/jira/rest/api/latest/issue/CRD-1  415 Unsupported Media Type (32ms)

响应以 HTML 形式返回。这是来自 tomcat 的响应正文:

<html><head><title>Apache Tomcat/6.0.20 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 415 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.20</h3></body></html>

这是我的 AJAX 调用(它本质上是包装在Atlassian gadget JavaScript Framework中的 JQuery ):

 args: [{
         key: "issueData",
         ajaxOptions: function() {
             return {
                 url: "/rest/api/latest/issue/CRDTRK-1"
             };
         }
  }]

我尝试添加dataType: "json"到 ajax 请求,但无济于事。我可能错过了一些简单的东西。

以下是请求/响应标头:

Response Headers
Content-Length  1051
Content-Type    text/html;charset=utf-8
Date    Sun, 10 Jun 2012 15:53:06 GMT
Server  Apache-Coyote/1.1
X-AREQUESTID    1013x5993x1
X-ASESSIONID    1bi5et0
X-AUSERNAME admin
X-Seraph-LoginReason    OK

Request Headers
Accept  application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-gb,en;q=0.5
Connection  keep-alive
Content-Type    application/x-www-form-urlencoded
Cookie  atlassian.xsrf.token=BP8Q-WXN6-SKX3-    
DNT 1
Host    10.0.15.10:2990
Referer http://10.0.15.10:2990/jira/secure/Dashboard.jspa
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
X-Requested-With    XMLHttpRequest
4

2 回答 2

6

您的小工具规范文件需要在您的 ajax 选项中发送 contentType 请求标头:

args: [{
    key: "issueData",
    ajaxOptions: function() {
        return {
            contentType: 'application/json',
            url: "/rest/api/2.0.alpha1/issue/CRDTRK-1"
        };
    },
}]

检查 HTTP 请求中的请求标头。应该是:Content-Type: application/json 而不是:Content-Type application/x-www-form-urlencoded

于 2012-06-11T09:55:30.440 回答
0

尝试使用 getJSON 和 out callBack=? 如:

$.getJSON('https://jira.atlassian.com/rest/api/latest/issue/JRA-9jsoncallback=?', function(data){ $.each(data, function(){ alert(this.expand); }); });
于 2012-06-10T17:01:09.633 回答