HttpClient请求的结果中中文显示乱码,可用UTF-8
来源:互联网 发布:mac 垃圾清理软件 编辑:程序博客网 时间:2024/06/06 02:56
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import org.apache.http.HttpResponse;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.DefaultHttpClient;import java.util.ArrayList;import java.util.regex.Matcher;import java.util.regex.Pattern;class HTTPGetSample {public static void main(String[] args) throws ClientProtocolException, IOException {String aString = getHTTPReturn("http://fund.eastmoney.com/data/rankhandler.aspx?op=ph&dt=kf&ft=all&rs=&gs=0&sc=zzf&st=desc&sd=2015-04-07&ed=2016-04-07&qdii=&tabSubtype=,,,,,&pi=1&pn=10000&dx=1&v=0.8509733614046127");ArrayList<String> fundNum = new ArrayList<String>();// 获取代码和名称fundNum.addAll(fundName("\"([0-9]+),(.+?),", aString));}public static ArrayList<String> fundName(String regex, String resource) {ArrayList<String> arrayList = new ArrayList<String>();Matcher m = Pattern.compile(regex).matcher(resource);while (m.find()) {arrayList.add(m.group());}return arrayList;}public static String getHTTPReturn(String url) throws ClientProtocolException, IOException {HttpClient client = new DefaultHttpClient();HttpGet request = new HttpGet(url);HttpResponse response = client.execute(request);BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));String tempStr;if ((tempStr = rd.readLine()) != null)return tempStr;elsereturn "";}}
0 0
- HttpClient请求的结果中中文显示乱码,可用UTF-8
- httpclient 的 doPost请求中文乱码问题
- 页面编码为UTF-8的项目中servlet中文显示乱码的解决方法
- 当从网页请求的内容中文显示为乱码时需要从 GBK 转到 UTF-8
- HttpClient请求中文乱码详解
- Atom中文显示乱码问题 UTF-8
- HttpClient Get请求中返回中文乱码问题解决
- 解决httpClient返回结果中文乱码
- tomcat设置为UTF-8,解析GBK编码的UTL请求,中文乱码处理
- HttpClient 发送Get请求 中文乱码
- python mysql中查询数据,结果中文显示乱码
- PLSQL中查询数据的时候查询结果显示中文乱码
- logback 中文显示乱码问题,设置utf-8格式
- 关于MySQL的dos客户端中文插入和显示utf-8乱码的解决方法
- php读中文显示乱码,怎么解决 php默认识别UTF-8的方法
- MySQL控制台显示结果的中文字符会出现乱码
- HttpClient中文乱码的解决方案
- 中文乱码转换utf-8
- rails中引入god
- Android 异步消息处理机制 让你深入理解 Looper、Handler、Message三者关系
- ubuntu下从源码编译比特币(Bitcoin)客户端
- C#-密度较量
- 2016蓝桥杯第二题 依旧水题
- HttpClient请求的结果中中文显示乱码,可用UTF-8
- Java中的length、length()、size的用法
- 使用存储过程进行分页查询
- ListView中显示不同的item
- Dalvik与ART的区别:
- CDOJ 1134 男神的约会
- 新手笔记之安卓自定义title标题栏使用
- 快速递归算法遍历生成De Bruijn序列
- 2016蓝桥杯第三题