Grails:用于JIRA基本身份验证的POST方法-不支持的媒体类型



我正在开发一个从JIRA数据库中提取数据的应用程序。我正在使用RESTClient API使用post方法进行基本身份验证。

完整代码(经过编辑):

class IssuesController {
    def xyz = this.encodeAuth("username", "password")
    def index() {
        def login = new RESTClient ('http://my-jira/rest/auth/1/')
        def response = login.post(
            path : 'session',
            headers : ['Authorization' : 'Basic ' + xyz + '=='])
        render response.data.toString()
    }
    public String encodeAuth(username, password) {
        def authC = username + ':' + password
        def bytes = authC.bytes
        return bytes.encodeBase64().toString();
    }

我收到一个带有消息Unsupported Media TypeHTTPResponseException。如果我使用get方法,则身份验证工作正常。(但它不会启动会话,所以没有用)。我甚至尝试更改标题headers : ['Content-Type' : 'application/json', 'Accept' : 'application/json']

使用FireBug分析网络头,Content-TypeAccept头仍然没有改变。

Response Headers
HTTP/1.1 500 Internal Server Error
Content-Type: text/html;charset=UTF-8
Content-Language: en-US
Connection: close

Request Headers
GET /GTPortal/issues/index HTTP/1.1
Host: localhost:8099
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate

使用POST时出现消息"不支持的媒体类型",有什么帮助吗!?

检查您的rest服务接受的请求数据类型,如application/json等,以及您的post请求中缺少的正文部分。RESTClient将把Accept: */*放在请求头中,并根据响应内容类型头中给出的内容解析响应。欲了解更多信息,请访问。http://groovy.codehaus.org/modules/http-builder/doc/rest.html

相关内容

最新更新