Frage

I am developing an application that extracts data from a JIRA database. I am using RESTClient API to do basic authentication using post method.

Full code (redacted):

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();
    }

I am getting an HTTPResponseException with a message Unsupported Media Type. If I use get method instead, the authentication works just fine. (But it doesn't start a session, so no use). I even tried changing the headers, headers : ['Content-Type' : 'application/json', 'Accept' : 'application/json'].

Used FireBug to analyze the network headers, the Content-Type and Accept headers still didn't change.

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

Any help why the message Unsupported Media Type when using POST!?

War es hilfreich?

Lösung

Check what kind of requested data accepting by your rest service like application/json or etc. and also missing body part in your post request. RESTClient will put Accept: */* in the request header, and parse the response based on whatever is given in the response content-type header.For more information visit. http://groovy.codehaus.org/modules/http-builder/doc/rest.html

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top