Get请求-Test版
2016-12-15 14:59
323 查看
package com.fanqi.test; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import org.apache.http.HttpEntity; 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; public class TestGet { public static void main(String[] args) { // TODO Auto-generated method stub HttpResponse hs = null; String url = "http://gc.ditu.aliyun.com/geocoding?a=%E8%8B%8F%E5%B7%9E%E5%B8%82"; HttpGet hg = new HttpGet(url); HttpClient hc = new DefaultHttpClient(); try { hs = hc.execute(hg); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } HttpEntity he = hs.getEntity(); try { InputStream in = he.getContent(); DataInputStream d = new DataInputStream(in); String str = d.readLine(); String str1 = str.substring(1, str.length()-1); String[] s = str1.split(","); for(int i=0;i<s.length;i++){ String t = s[i]; String[] tt = t.split(":"); if(tt.length==2){ String key = tt[0].replace("\"", ""); String value = tt[1].replace("\"", ""); System.out.println(key + ":" + value); }else{ String key = tt[0].replace("\"", ""); System.out.println(key + ":" + "null"); } } } catch (IllegalStateException | IOException e) { e.printStackTrace(); } } }
相关文章推荐
- Servlet处理get请求时的中文乱码问题
- Http与HttpClient(已被废弃)通信的介绍,附带一个Http发送GET请求工具类的例子
- ajax_之get请求方式(ajax验证用户名)
- Tomcat在处理GET和POST请求时产生的乱码问题
- IOS之同步请求、异步请求、GET请求、POST请求
- HTTP的GET和POST请求
- Http中的Post和GET请求的区别
- get请求中文乱码
- 过滤器实现get请求乱码问题
- android post和get请求 && 子线程获取UI线程的值
- AFNetworking GET 请求 方法封装及调用
- 新浪授权登录 正确的获取access_token (都不能用curl请求,包括微信授权登录 ) 要用file_get_contents
- HTTP请求方式之GET和POST比较
- Android HTTP实例 使用GET方法和POST方法发送请求
- HTTP GET/POST请求区别
- asp.net获取传值get和post请求
- ajax的GET和POST请求
- 对于携带请求参数的HttpGet与的HttpPost两种请求方式,代码段分析
- Alamofire的get请求,post请求,以及上传字典
- 【iOS开发-93】GET和POST请求的实现步骤,MD5加密方法