[英]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.