Tag: multibyte

带有中文字符的无效URI(Java)

无法在URL中设置包含中文字符的URL连接。 它适用于拉丁字符: String xstr = “维也纳恩斯特哈佩尔球场” ; URI uri = new URI(“http”,”ajax.googleapis.com”,”/ajax/services/language/detect”,”v=1.0&q=”+xstr,null); URL url = uri.toURL(); URLConnection connection = url.openConnection(); InputStream is = connection.getInputStream() ; getInputStream()调用导致: java.lang.IllegalArgumentException: Invalid uri ‘http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=???????????’: Invalid query