HttpClient——Post请求
来源:互联网 发布:万思软件开发有限公司 编辑:程序博客网 时间:2024/06/05 02:55
//为以下拼接请求地址public String path="";public String key="";public String pno="";public String ps="";try { // 创建客户端 HttpClient client = new DefaultHttpClient(); // 创建post对象 HttpPost post = new HttpPost(path); ArrayList<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>(); list.add(new BasicNameValuePair("key", key)); list.add(new BasicNameValuePair("pno", pno)); list.add(new BasicNameValuePair("ps", ps)); HttpEntity entity = new UrlEncodedFormEntity(list); // 发送内容 post.setEntity(entity); // 发送请求 HttpResponse response = client.execute(post); //得到请求码 int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) { // 得到实体内容 InputStream inputStream = response.getEntity() .getContent(); int len; byte[] b = new byte[1024]; ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); while ((len = inputStream.read(b)) != -1) { arrayOutputStream.write(b, 0, len); } String strJson = arrayOutputStream.toString(); //handler向主线程发送信息,更新数据 handler.obtainMessage(SUCCESS, strJson).sendToTarget(); } } catch (Exception e) { e.printStackTrace();}
0 0
- HttpClient——Post请求
- UWP——HttpClient模拟浏览器的GET、POST请求
- HTTPClient跨域访问 ——Post请求
- HttpClient--HttpClient的Post请求
- Httpclient发送POST请求
- httpClient发送post请求
- HttpClient发起post请求
- HttpClient post 请求实例
- HttpClient发起POST请求
- httpclient Post请求
- httpclient post请求
- HttpClient Post请求
- httpclient post/set请求
- HttpClient发送post请求
- httpclient发送post请求
- httpClient post/get请求。
- httpClient post请求设置
- HttpClient get,Post请求
- 1006. 换个格式输出整数 (15)
- 博弈论(转)
- Actor模型和CSP模型的区别
- Eclipse上安装GIT插件EGit及使用
- C语言中的atoi函数的实现
- HttpClient——Post请求
- IMF传奇行动第84课:Spark Streaming第三课:StreamingContext、DStream、Receiver深度剖析
- hdu1540 Tunnel Warfare(线段树区间合并详解)
- Fresco之客户端与服务端的交互
- 北大百练+简单递归回溯+就是那个变量类型弄错了,才搞错的额
- PHP数组基础知识总结以及排序
- 计算复杂性学习1-单带图灵机模拟
- Fresco.initializeDrawee()的过程
- UVA 10305 拓扑排序(基础)