0
我正在写一个从URL到URI的转换,仅用于将java.net.URI作为参数的Http方法。如何避免java.net.URI中的冗余双重编码?
我的实现是这样的:
new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), null);
所以不会对具有空间(不正确的网址为借口)URL打破。但是,在编码以下url时:
http://www.****.ca/en-ca/Catalog/Gallery.aspx?ID=Mass%20Spectrometry%20[GC/MS%20and%20ICP-MS]&PID=Gas%20Chromatography%20Mass%20Spectrometry%20Consumables
它会将所有%20转换为%2520,从而导致地址无效。
Java中有没有一种方法可以正确解析各种URL?包括具有%20和空格的那些?像浏览器或wget命令一样。