简体   繁体   English

URLConnection URL包含重音字符的编码问题

[英]Encoding issue with URLConnection URL containing accented characters

I am using URLConnection to connect with my Apache server to download files. 我正在使用URLConnection与我的Apache服务器连接以下载文件。

If I use this url : http://myserver.com/files/ete.ext - it works however if I make http://myserver.com/files /été.ext it doesn't work. 如果我使用以下网址: http ://myserver.com/files/ete.ext-可以,但是如果我使用http://myserver.com/files/été.ext则无法使用。

Any help please? 有什么帮助吗?

Use this function: 使用此功能:

$address = iconv('ISO-8859-1', 'UTF-8', $address);

I hope this will be helpful, if iconv extension is available 如果iconv扩展可用,我希望这会有所帮助

I had a similar issue while working with the google maps API. 使用Google Maps API时遇到类似的问题。 Certain places had accented characters and it didn't work properly. 某些地方的字符带有重音,因此无法正常工作。 My workaround (it is probably pretty sloppy) was to simply replace all of the accented characters with non-accented ones. 我的解决方法(可能很草率)是将所有带重音的字符替换为非带重音的字符。

I simply called the replaceAll function for all of my strings and got rid of all of the invalid characters. 我只是为所有字符串调用了replaceAll函数,并摆脱了所有无效字符。

I hope this helps 我希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM