HttpURLConnection请求出现乱码解决方案
来源:互联网 发布:驾考模拟软件 编辑:程序博客网 时间:2024/05/17 00:56
之前一直用的Httpclient,请求的时候没出现过问题,因为android 6.0中网络请求删掉了httpclient,就准备试试HttpURLConnection
String str = "http://220.248.121.170:6687/temp/CPHS_CLI_192.168.1.68.xml"; try { String date = ""; URL url = new URL(str); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); if (connection.getResponseCode()==200) { BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8")); BufferedReader bufferReader = new BufferedReader(reader); String inputLine = ""; while((inputLine = bufferReader.readLine()) != null){ date += inputLine + "\n"; } System.out.println(date); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
请求结果是
,百度了半天,尝试了各种解决方案,最后改了一个地方
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-16LE"));
编码方式改为UTF-16LE
?<callList> <callPerson> <pId></pId> <roomID>2_1</roomID> <pName>214号张世昌</pName> <fWav>请全科二214号 张世昌 到1诊室就诊</fWav> <upTime>2015-08-26 15:25</upTime> <reFreshTime>3</reFreshTime> </callPerson></callList>
ok,没问题了
0 0
- HttpURLConnection请求出现乱码解决方案
- HttpURLConnection请求后,返回数据出现乱码解决办法!
- 用HttpURLConnection请求网页的时候会出现中文乱码
- 使用HttpURLConnection,请求结果乱码。
- HttpURLConnection 请求webservice出现错误
- post和get请求中文参数出现乱码现象解决方案
- HTTP请求json文件出现中文乱码的解决方案
- 使用HttpUrlConnection执行Post请求,出现EOFException
- 应用程序出现乱码解决方案
- Ajax请求中文乱码解决方案
- Tomcat: 在tomcat5下的get请求会出现乱码的解决方案?
- get请求方式中可能出现的乱码问题的解决方案
- Android Volley请求出现乱码
- Android Volley请求出现乱码
- (一)HttpURLConnection之Get请求(解决乱码)
- 使用HttpURLConnection采用get方式请求数据-----乱码问题
- 解决HttpURLConnection请求时传中文参数乱码问题
- Java HttpURLConnection模拟请求Rest接口解决中文乱码问题
- 4、DatabaseLibrary 库-数据库的应用
- innodb存储引擎的线程
- node.js was not found in the default path
- 5、Robot Framework必须掌握的库----BuiltIn库
- MYSQL未启用存储引擎的启用办法
- HttpURLConnection请求出现乱码解决方案
- Linux的权限和所有权模型
- androidstudio 常用快捷键
- 全面理解Unity加载和内存管理
- ajax 实现当输入用户名或手机号找回密码的前台操作
- python中获得某月有多少天的函数
- ExtJs 实现动态列,动态多表头
- [API]common http get and post
- Log4j.properties 详解