groovy-wslite icon indicating copy to clipboard operation
groovy-wslite copied to clipboard

HTTPClient.defaultCharset is ignored in case of charset is not specified in content type header,

Open yeoupooh opened this issue 9 years ago • 2 comments

Hi,

I'm trying to use groovy-wslite instead of httpbuilder because of convenient APIs. My example Korean site ( http://clien.net/ ) is encoded to 'UTF-8' but charset isn't specified in content type header. So it is converted 'iso-8859-1' by default in HttpResponse.getContentAsString(). This response text would be unreadable for Korean.

In this case, if user set defaultCharset of HTTPClient as 'UTF-8', can it be used in HttpResponse.getContentAsString() with defaultCharset?

Thanks in advance.

Best Regards, Thomas

yeoupooh avatar Jul 07 '15 12:07 yeoupooh

Here is an example:

def url = "http://clien.net"
def client = new RESTClient(url)
client.defaultCharset = "UTF-8"
def response = client.get()
// response.charset is null
println "response.charset=" + response.charset
// response.text is converted to 'iso-8859-1' from 'UTF-8',
println "response.text=" + response.text

yeoupooh avatar Jul 07 '15 23:07 yeoupooh

Here is my quick fix.

https://github.com/yeoupooh/groovy-wslite/tree/issue100_patch

yeoupooh avatar Jul 08 '15 00:07 yeoupooh