Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTPBuilder encoding utf-8 in Grails

Tags:

utf-8

grails

I have a problem using HTTPBuilder in Grails.

The code is something like this.

def http = new HTTPBuilder("theURL")

http.request(method, ContentType.JSON) {
    uri.path = "theURI"

    headers.'Authorization' = "OAuth  $accessToken"
    headers.'Accept' = "application/json"
    headers.'content-type' = "application/json;charset=utf-8"

    response.success = { resp, json ->
        result = json
    }
}

return result

Now the response is a JSON with "Cobro N�� 1234" but i need "Cobro Nº 1234"

I tried this with curl and the response is fine "Cobro Nº 1234", this made me think that the problem is the HTTPBuilder and not my API who response the request.

I think that it is a problem with the response encoding.

like image 604
dimartiro Avatar asked Nov 10 '22 15:11

dimartiro


1 Answers

http.encoders.charset = Charsets.UTF_8
like image 88
Michael Griffel Avatar answered Nov 15 '22 06:11

Michael Griffel