使用德语字符编码URL [英] Encoding URL with German Characters

查看:212
本文介绍了使用德语字符编码URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我收到一个URL,例如

In my app I receive a URL such as


http://www.wassersportlotse.de/php/lib/smart_image_resizer/image.php/Mühlendammschleuse.jpg?image=/media/images/uploads/Mühlendammschleuse.jpg


当fullurl中没有德语字符时,我可以在没有编码的情况下使用它,它可以正常工作。但是,如果我收到一个如上所示的URL,则它不起作用(ü导致问题)。下面我试图编码URI的单独部分无济于事。非常感谢alway建议。

When there are no German characters in the fullurl I can just use it without encoding and it works fine. However if I receive a URL such as the one above it doesn't work (the ü is causing the problem). Below I have tried to encode the seperate parts of the URI to no avail. As alway advice is very much appreciated.

public ImageDownloader(String fullurl) throws URISyntaxException{
    URI uri = new URI(fullurl);

    path = uri.getPath();
    path = URLEncoder.encode(path);

    query = uri.getQuery();
    query = URLEncoder.encode(query);

    auth = uri.getAuthority();

    url = "http://" + auth + path + query;


}


推荐答案

也许编码器das将变音符号编码为UTF-8字符(因此ü将被编码为两个字符)并且它们不会在服务器上正确放回(对我们来说它不适用于Tomcat)。为解决这种情况,我们使用 URLEncoder.encode(param,ISO-8859-1)对参数进行编码。

Maybe the encoder das encode the Umlaut as UTF-8 characters (so ü would be encoded with two characters) and they are not put back together properly at the server (for us it didn't work with Tomcat). To solve this situation we used URLEncoder.encode(param, "ISO-8859-1") to encode the parameters.

这篇关于使用德语字符编码URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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