[英]Read non-english characters from http get request
I have a problem in getting Hebrew characters from a http get request. 我从http get请求中获取希伯来字符时遇到问题。
I'm getting squares characters like this: "[]" instead of the Hebrew characters. 我得到这样的正方形字符:“ []”,而不是希伯来字符。
The English characters are Ok. 英文字符可以。
This is my function: 这是我的功能:
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();
}
}
}
}
You can test is by this example url: 您可以通过以下示例网址进行测试:
String str = executeHttpGet("http://kavim-t.co.il/include/getXMLStations.asp?parent=7_%20_1");
Thank you! 谢谢!
The file you linked to doesn't seem to be UTF-8
. 您链接到的文件似乎不是
UTF-8
。 I tested that it opens correctly using WINDOWS-1255
(hebrew encoding), you should try that instead of UTF-8
. 我测试了它是否可以使用
WINDOWS-1255
(希伯来语编码)正确打开,您应该尝试使用它而不是UTF-8
。
Try a different website, it looks like it doesn't use UTF-8. 尝试使用其他网站,看起来它没有使用UTF-8。 Alternatively, UTF-16 may work but I haven't tried.
另外,UTF-16 可能可以工作,但我没有尝试过。 Your code looks fine.
您的代码看起来不错。
As others have pointed out, the content is not actually encoded as UTF-8. 正如其他人指出的那样,内容实际上并未编码为UTF-8。 You might want to look at
httpEntity.getContentType()
to extract the actual encoding of the content, and then pass this to your InputStreamReader
. 您可能希望查看
httpEntity.getContentType()
以提取内容的实际编码,然后将其传递给InputStreamReader
。 This means your code will then be able to cope correctly with any encoding. 这意味着您的代码将能够正确处理任何编码。
hi as is posted in this other question Special characters in PHP / MySQL 您好,在其他问题中发帖PHP / MySQL中的特殊字符
you can set the characters on the php file on the example they set utf-8, but you can set a different type that supports the chararcters you need. 您可以在设置utf-8的示例中在php文件上设置字符,但可以设置支持所需字符的其他类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.