Java – what is the difference between these two urlencodings of URL

Some queries encoded UTF - 8 I sent to the server did not return the expected results

Namely

http://direct.jthinkws.com?type=release&query=artist%3A%28Dinosaur%7E0.7 +AND+Jr.%29++AND++%28%2Btrack%3A%22Forget+The+Swan%22+%2Btrack%3A%22Just+Like+Heaven%22+%29++AND+tracks%3A%5B2+TO+100%5D++AND+src%3A1&limit=20&offset=0

Only two results are returned in my application (the results are returned in XML). If it is directly put into Firefox browser, only two results are returned

However, if I put an uncoded URL value into Firefox

http://direct.jthinkws.com?type=release \u0026amp; Query = Artist: (Dinosaur ~ 0.7 and Jr.) and (track: "forget the swan" track: "just like heaven") and track: [2 to 100] and Src: 1 & limit = 20 & offset = 0

It returns 44 files

From my server, I can see that I get the following request. I think it must be Firefox encoded data

http://direct.jthinkws.com?type=release&query=artist: (Dinosaur~0.7%20AND%20Jr.)% 20%20AND%20%20(+track:”Forget%20The%20Swan”%20+track:”Just%20Like%20Heaven”%20)%20%20AND%20tracks:[2%20TO%20100]%20%20AND%20src:1&limit=20&offset=0

You can see that it is encoded slightly differently - spaces are converted to "not" and '(' and ')' are not converted

I don't understand the difference, why one works, one doesn't, and why something that doesn't work does return some less results

(I also tried to encode it as iso-8859-1 instead of UTF-8) and it failed completely. The server can't decode it, so I'm sure utf8 is the correct encoding

My code is written in Java. It uses urencoder to encode the value of the query, i.e

String query = URLEncoder.encode(queryValue.toString(),StandardCharsets.UTF_8.name());

Solution

I have this wrong way around my code that actually works well. It should only return two results

The problem is that Firefox can't encode correctly, assuming they are already coding space As a result, you cannot always rely on Firefox to correctly encode the uncoded web address pasted into it

This problem is not specific to Firefox, and perhaps no browser can manage to code correctly So be careful if you use URLs that include

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>