url的这两个urlencoding之间存在差异的原因是什么 [英] What is the reason for the difference between these two urlencodings of url

查看:79
本文介绍了url的这两个urlencoding之间存在差异的原因是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发送到服务器的某些编码为UTF-8的查询未返回预期结果.

Some queries encoded as UTF-8 that I send to a server are not returning the expect results.

在我的应用程序中仅返回两个结果(结果以Xml返回),如果直接放入Firefox浏览器,则仅返回2个结果

is only returning two results (results are returned as Xml) in my application and only 2 results if I put directly into Firefox browser

但是,如果我将未编码的url值放入Firefox

However if I put the non-encoded url value into Firefox

http://direct.jthinkws.com?type=release&query=artist :(恐龙〜0.7与小.)AND(+曲目:忘记天鹅" +曲目:就像天堂一样")AND曲目:[2 TO 100] AND src:1& limit = 20& offset = 0

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

它返回44个文件

从服务器上我可以看到我收到以下请求,我认为该请求必须是对数据进行Firefox编码的

and from my server I can see I get the following request which I assume must be firefox encoding the data

如您所见,它的编码方式略有不同-空格将转换为'%20'而不是'+'且'('和')'不会转换.

as you can see it is encoding it slightly differently - spaces are being converted to '%20' not '+' and '(' and ')' are not converted.

我不了解其中的区别,为什么一个有效,一个无效,为什么不起作用确实返回了一些结果,却没有那么多.

I dont understand the difference and why one works and one doesn't, also why the one that doesnt work does return some results just not as many.

(我也尝试使用ISO-8859-1而不是UTf-8进行编码),并且完全失败,服务器无法对其进行解码,因此我确定UTf8是正确的编码.

(Also I tried encoding as ISO-8859-1 instead of UTf-8) and that completely failed the server couldnt decode it so Im sure UTf8 is the correct encoding.

我的代码是用Java编写的,并且使用UREncoder对查询的值进行编码,即

My code is written in Java and its encodes the value of the query using UREncoder, i.e

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

推荐答案

我在我的代码运行正常时遇到了这种错误方式,它应该只返回两个结果.

I had this the wrong way round my code was actually working fine it should only return two results.

问题是,假设Firefox已经编码为空格,则Firefox无法对其进行正确编码.因此,您不能总是依靠Firefox对粘贴到其中的未编码网址进行正确编码.

The problem was that Firefox was unable to correctly encode the +'s assuming them to be already encoded spaces. So you cant always rely on Firefox to correctly encode a unencoded url that you paste into it.

此问题并非特定于Firefox,可能是没有浏览器能够正确编码.因此,如果您使用的网址中包含"+",请务必小心.

This problem is not specific to Firefox, it maybe that no browser could manage to encode this properly. So if you are using a url that includes '+'s be careful.

这篇关于url的这两个urlencoding之间存在差异的原因是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆