[英]Read non-english characters from http get request
我从http get请求中获取希伯来字符时遇到问题。
我得到这样的正方形字符:“ []”,而不是希伯来字符。
英文字符可以。
这是我的功能:
public String executeHttpGet(String urlString) throws Exception {
BufferedReader in = null;
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(urlString));
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(),"UTF-8"));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String page = sb.toString();
// System.out.println(page);
return page;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
您可以通过以下示例网址进行测试:
String str = executeHttpGet("http://kavim-t.co.il/include/getXMLStations.asp?parent=7_%20_1");
谢谢!
您链接到的文件似乎不是UTF-8
。 我测试了它是否可以使用WINDOWS-1255
(希伯来语编码)正确打开,您应该尝试使用它而不是UTF-8
。
尝试使用其他网站,看起来它没有使用UTF-8。 另外,UTF-16 可能可以工作,但我没有尝试过。 您的代码看起来不错。
正如其他人指出的那样,内容实际上并未编码为UTF-8。 您可能希望查看httpEntity.getContentType()
以提取内容的实际编码,然后将其传递给InputStreamReader
。 这意味着您的代码将能够正确处理任何编码。
您好,在其他问题中发帖PHP / MySQL中的特殊字符
您可以在设置utf-8的示例中在php文件上设置字符,但可以设置支持所需字符的其他类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.