Jsoup.connect(string) encoding issues

前端 未结 2 1142
我寻月下人不归
我寻月下人不归 2021-01-18 11:05

I have several special character url\'s i have to connect to with Jsoup.connect(string), but it fails to load the page (getting a error 500). I\'m not really that much into

2条回答
  •  情书的邮戳
    2021-01-18 11:27

    Running into URL-encoding problems, I'd recommend you parse your request using a URL encoder tool first (StackOverflow answer regarding those). One already comes with Java.

    URLEncoder.encode(stringToBeEncoded, "UTF-8") 
    

    Using it on your unformatted string above, it should look something like:

    Document gDoc = JSoup.connect(placesURL.format(URLEncoder.encode(queryString, "UTF-8"));
    

    ... as to not URL-encode your entire URL, just the part of the query you need to be UTF-8 (or UTF-16) compliant.

提交回复
热议问题