lu20091563
lu20091563
2014-05-10 03:19

HttpClient请求网址返回javascript乱码

  • httpclient

实现代码如下:

public static String getHtml() { 
        String response = ""; 
        HttpClient client = new HttpClient(); 
        HttpMethod method = new GetMethod("http://static1.mtime.cn/Utility/Data/TheaterListBoxData.m");
        try { 
                client.executeMethod(method); 
                if (method.getStatusCode() == HttpStatus.SC_OK) { 
                        System.out.println(method.getResponseBodyAsString());
//                        response = method.getResponseBodyAsString(); 
                } 
        } catch (URIException e) { 
                e.printStackTrace();
                return null;
        } catch (IOException e) { 
                e.printStackTrace();
                return null;
        } finally 
        { 
                method.releaseConnection(); 
        }
        
        return response; 

    }

 请求这个路径http://static1.mtime.cn/Utility/Data/TheaterListBoxData.m就有问题,因为返回的是text/javascript;

看到别人说说method.getResponseBodyAsStream()返回流,再设置流的字符编码,循环读取出来的也是乱码!

求解决方案!

 

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐