我正在开发一个从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();
}
我收到带有消息
HTTPResponseException
的Unsupported Media Type
。如果我改用获取方法,则身份验证工作正常。 (但是它不会启动 session ,因此没有用)。我什至尝试更改标题headers : ['Content-Type' : 'application/json', 'Accept' : 'application/json']
。使用FireBug分析网络 header ,但
Content-Type
和Accept
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/