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

标签 grails post jira rest-client

我正在开发一个从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();
    }

我收到带有消息HTTPResponseExceptionUnsupported Media Type。如果我改用获取方法,则身份验证工作正常。 (但是它不会启动 session ,因此没有用)。我什至尝试更改标题headers : ['Content-Type' : 'application/json', 'Accept' : 'application/json']

使用FireBug分析网络 header ,但Content-TypeAccept header 仍未更改。
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!时为什么出现消息“不支持的媒体类型”有什么帮助吗?

最佳答案

检查您的其他服务(例如application / json或其他)接受哪种类型的请求数据,以及在后期请求中是否缺少正文部分。
RESTClient将Accept: */*放在请求 header 中,并根据响应内容类型 header 中给出的内容解析响应。有关更多信息,请访问。
http://groovy.codehaus.org/modules/http-builder/doc/rest.html

关于grails - Grails:JIRA基本身份验证的POST方法-不支持的媒体类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18547499/

相关文章:

grails - 用于保存的Grails GORM域类关系

grails - 选择 View 时插件之间的优先级

iphone - 如何销毁NSHTTPCookies?

php - php输出完成后通过jquery ajax加载内容

ruby - Jira Rest API - 如何登录

java - 在 Jira 插件的速度模板方面需要一些帮助

grails - 为连接到另一个域的复合主键的外键创建 Grails 域映射

grails - 我是否需要做一些特殊的事情才能使命令对象在grails中实例化?

android - 如何使用 POST 使用 NameValuePair 将参数添加到 HttpURLConnection

jira - 为什么我无法将用户添加到 Atlassian 的 Jira 中的角色?