Trying to replicate a successful POST request with JSoup - data posted to server does not get decoded

后端 未结 1 1406
感动是毒
感动是毒 2021-01-14 14:24

Http request header:

Host: www.mysite.com
Content-Type: application/x-www-form-urlencoded
Cookie: bbuserid=XXX; bbpassword=YYY; bbsessionhas         


        
相关标签:
1条回答
  • 2021-01-14 14:59

    Jsoup uses UTF-8 by default to URL-encode the query string. With the current API version, you cannot change it without rebuilding the source (it's the org.jsoup.helper.DataUtil#defaultCharset constant which is been used in org.jsoup.helper.HttpConnection class). Best what you can do is to post an issue report requesting the ability to preset the charset beforehand.

    Until then, you could use HttpClient or URLConnection instead which allows for a more finer grained control over sending HTTP requests. You could finally feed its response as an InputStream to Jsoup#parse() method.


    Update: if the target website supports it, you could try explicitly specifying the client's used charset in the Content-Type request header:

    .header("Content-Type","application/x-www-form-urlencoded;charset=UTF-8")
    

    Note that you should not use URLEncoder#encode() yourself; let Jsoup do its job.

    0 讨论(0)
提交回复
热议问题