Android Java UTF-8 HttpClient Problem

后端 未结 5 2188
自闭症患者
自闭症患者 2020-12-01 04:35

I am having weird character encoding issues with a JSON array that is grabbed from a web page. The server is sending back this header:

Content-Type text/javascri

5条回答
  •  独厮守ぢ
    2020-12-01 05:36

    Archimed's answer is correct. However, that can be done simply by providing an additional header in the HTTP request:

    Accept-charset: utf-8
    

    No need to remove anything or use any other library.

    For example,

    GET / HTTP/1.1
    Host: www.website.com
    Connection: close
    Accept: text/html
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.10 Safari/537.36
    DNT: 1
    Accept-Encoding: gzip, deflate, sdch
    Accept-Language: en-US,en;q=0.8
    Accept-Charset: utf-8
    

    Most probably your request doesn't have any Accept-Charset header.

提交回复
热议问题