实现代码如下:
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()返回流,再设置流的字符编码,循环读取出来的也是乱码!
求解决方案!