androidhttpclient用android的httpclient抓网页(GET)有的可以,有的网页抓不到,请求头设置了。

androidhttpclient  时间:2021-06-12  阅读:()

安卓怎么使用httpclient

构造完整的URL 设置一段间隔时间参数,保证HTTP连接顺利建立成功 构造HttpClient的实例,并传入Httpparams参数 创建GET方法的实例,并传入URL地址 使用httpclient执行httpGet进行联网,返回httpResponse(带有数据) 获得返回结果,并将数据变成String类型,方便使用JSON进行解析

android httpclient 怎样实现将安卓的一段数据(字符串)上传到服务器 服务器php+apache 怎么接收

手机端的------// 提交反馈信息,这是post方式提交 服务端,php不懂说以,你再找找,跟客户端关系不大 public String user_feedback(String feedbackType,String feedbackContent,String contacts) { ArrayList<NameValuePair> nv=new ArrayList<NameValuePair>(); nv.add(new BasicNameValuePair("userId", this.user.userid)); nv.add(new BasicNameValuePair("feedbackType", feedbackType)); nv.add(new BasicNameValuePair("feedbackContent",feedbackContent)); nv.add(new BasicNameValuePair("userContact",contacts)); nv.add(new BasicNameValuePair("permit", this.user.permit)); DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(uri); String strResult = ""; try { HttpEntity entity = new UrlEncodedFormEntity(nv, "UTF-8"); post.setEntity(entity); // 获得HttpResponse对象 HttpResponse httpResponse = client.execute(post); if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // 取得返回的数据 strResult = EntityUtils.toString(httpResponse.getEntity()); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.i("jsonHelper", strResult); return strResult; }

用android的httpclient抓网页(GET)有的可以,有的网页抓不到,请求头设置了。

可使用android自带的httpclient框架实现。

1. GET 方式传递参数 //先将参数放入List,再对参数进行URL编码 List params = new LinkedList(); params.add(new BasicNameValuePair("param1", "数据")); //增加参数1 params.add(new BasicNameValuePair("param2", "value2"));//增加参数2 String param = URLEncodedUtils.format(params, "UTF-8");//对参数编码 String baseUrl = "服务器接口完整URL"; HttpGet getMethod = new HttpGet(baseUrl + "?" + param);//将URL与参数拼接 HttpClient httpClient = new DefaultHttpClient(); try { HttpResponse response = httpClient.execute(getMethod); //发起GET请求 Log.i(TAG, "resCode = " + response.getStatusLine().getStatusCode()); //获取响应码 Log.i(TAG, "result = " + EntityUtils.toString(response.getEntity(), "utf-8"));//获取服务器响应内容 } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } 2. POST方式 方式传递参数 //和GET方式一样,先将参数放入List params = new LinkedList(); params.add(new BasicNameValuePair("param1", "Post方法"));//增加参数1 params.add(new BasicNameValuePair("param2", "第二个参数"));//增加参数2 try { HttpPost postMethod = new HttpPost(baseUrl);//创建一个post请求 postMethod.setEntity(new UrlEncodedFormEntity(params, "utf-8")); //将参数填入POST Entity中 HttpResponse response = httpClient.execute(postMethod); //执行POST方法 Log.i(TAG, "resCode = " + response.getStatusLine().getStatusCode()); //获取响应码 Log.i(TAG, "result = " + EntityUtils.toString(response.getEntity(), "utf-8")); //获取响应内容 } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }

hostkey俄罗斯、荷兰GPU显卡服务器/免费Windows Server

Hostkey.com成立于2007年的荷兰公司,主要运营服务器出租与托管,其次是VPS、域名、域名证书,各种软件授权等。hostkey当前运作荷兰阿姆斯特丹、俄罗斯莫斯科、美国纽约等数据中心。支持Paypal,信用卡,Webmoney,以及支付宝等付款方式。禁止VPN,代理,Tor,网络诈骗,儿童色情,Spam,网络扫描,俄罗斯色情,俄罗斯电影,俄罗斯MP3,俄罗斯Trackers,以及俄罗斯法...

快云科技,美国VPS 2H5G独享20M 仅售19.8/月  年付仅需148

快云科技已稳步运行进两年了 期间没出现过线路不稳 客户不满意等一系列问题 本司资质齐全 持有IDC ICP ISP等正规手续 有独特的网站设计理念 在前几天刚是参加过魔方系统举行的设计大赛拿获最佳设计奖第一名 本公司主营产品 香港弹性云服务器,美国vps和日本vps,香港物理机,国内高防物理机以及美国日本高防物理机 2020年的国庆推出过一款香港的回馈用户特惠机 已作为传家宝 稳定运行 马上又到了...

cyun29元/月,香港CN2 GIA云服务器低至起;香港多ip站群云服务器4核4G

cyun怎么样?cyun蓝米数据是一家(香港)藍米數據有限公司旗下品牌,蓝米云、蓝米主机等同属于该公司品牌。CYUN全系列云产品采用KVM架构,SSD磁盘阵列,优化线路,低延迟,高稳定。目前,cyun推出的香港云服务器性价比超高,香港cn2 gia云服务器,1核1G1M/系统盘+20G数据盘,低至29元/月起;香港多ip站群云服务器,16个ip/4核4G仅220元/月起,希望买香港站群服务器的站长...

androidhttpclient为你推荐
匹配函数计算机中的vlookup函数怎么使用人肉搜索引擎怎样使用人肉搜索引擎?搜索引擎的概念搜索引擎营销的概念是什么?防火墙排名什么防火墙世界第一啊?(急!!!)数据挖掘项目怎样利用大数据挖掘农业项目发展前景数据挖掘项目将来想从事统计分析和数据挖掘,需要哪些技能腾讯技术腾讯QQ是谁研发的?在那一年上市的?币众筹收益权众筹为什么有吸引力微软操作系统下载怎么下载官方win10 64位镜像系统kjava谁能告诉我KJAVA是什么意思和普通的JAVA程序有什么区别?
出租服务器 directspace 国外idc 特价空间 suspended 台湾谷歌网址 福建天翼加速 个人域名 空间合租 万网空间购买 个人免费主页 alexa世界排名 winserver2008下载 ubuntu安装教程 vi命令 好看的空间留言 电脑主机嗡嗡响 英国伦敦塔桥 .中国域名 永久免费网络加速器 更多