阅读从HTTP GET请求非英文字符 [英] Read non-english characters from http get request

查看:92
本文介绍了阅读从HTTP GET请求非英文字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在得到希伯来文字符从HTTP GET请求的问题。

I have a problem in getting Hebrew characters from a http get request.

我收到方块文字是这样的:[],而不是希伯来字符

I'm getting squares characters like this: "[]" instead of the Hebrew characters.

在英文字符都OK。

这是我的功能:

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");

感谢您!

推荐答案

您联系似乎并没有被文件 UTF-8 。我测试了一下它使用 WINDOWS-1255 (希伯来文编码)正确打开,你应该尝试,而不是该 UTF-8

The file you linked to doesn't seem to be UTF-8. I tested that it opens correctly using WINDOWS-1255 (hebrew encoding), you should try that instead of UTF-8.

这篇关于阅读从HTTP GET请求非英文字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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