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(); }

搬瓦工VPS:新增荷兰机房“联通”线路的VPS,10Gbps带宽,可在美国cn2gia、日本软银、荷兰“联通”之间随意切换

搬瓦工今天正式对外开卖荷兰阿姆斯特丹机房走联通AS9929高端线路的VPS,官方标注为“NL - China Unicom Amsterdam(ENUL_9)”,三网都走联通高端网络,即使是在欧洲,国内访问也就是飞快。搬瓦工的依旧是10Gbps带宽,可以在美国cn2 gia、日本软银与荷兰AS9929之间免费切换。官方网站:https://bwh81.net优惠码:BWH3HYATVBJW,节约6...

10gbiz首月半价月付2.36美元,香港/洛杉矶VPS、硅谷独立服务器/站群服务器

收到10gbiz发来的7月份优惠方案,中国香港、美国洛杉矶机房VPS主机4折优惠码,优惠后洛杉矶VPS月付2.36美元起,香港VPS月付2.75美元起。这是一家2020年成立的主机商,提供的产品包括独立服务器租用和VPS主机等,数据中心在美国洛杉矶、圣何塞和中国香港。商家VPS主机基于KVM架构,支持使用PayPal或者支付宝付款。洛杉矶VPS架构CPU内存硬盘带宽系统价格单核512MB10GB1...

PacificRack(19.9美元/年)内存1Gbps带vps1GB洛杉矶QN机房,七月特价优惠

pacificrack怎么样?pacificrack商家发布了七月最新优惠VPS云服务器计划方案,推出新款优惠便宜VPS云服务器采用的是国产魔方管理系统,也就是PR-M系列,全系基于KVM虚拟架构,这次支持Windows server 2003、2008R2、2012R2、2016、2019、Windows 7、Windows 10以及Linux等操作系统,最低配置为1核心2G内存1Gbps带宽1...

androidhttpclient为你推荐
李智慧韩智慧的全部资料股价图简单易懂的股票图外加说明应用雷达雷达是什么东西eagleeye电脑进程中出现Eaglesvr这种程序,据说是一种蠕虫病毒。。。怎样杀掉?jstz请帮忙翻译腾讯技术腾讯是什么东西?微信智能机器人有没有可以拉进微信群的聊天机器人kjavaJava与KJava有什么区别吗.?bt代理有人推荐我成为btbank代理人,这个没有什么风险?收费视频怎么制作收费视频
日本私人vps hostigation 国内免备案主机 pw域名 英文简历模板word 牛人与腾讯客服对话 小米数据库 骨干网络 智能骨干网 河南移动邮件系统 宁波服务器 已备案删除域名 稳定免费空间 电信虚拟主机 支付宝扫码领红包 上海联通宽带测速 申请免费空间和域名 web服务器搭建 湖南idc 摩尔庄园注册 更多