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

JUSTG(5.99美元/月)最新5折优惠,KVM虚拟虚拟512Mkvm路线

Justg是一家俄罗斯VPS云服务器提供商,主要提供南非地区的VPS服务器产品,CN2高质量线路网络,100Mbps带宽,自带一个IPv4和8个IPv6,线路质量还不错,主要是用户较少,带宽使用率不高,比较空闲,不拥挤,比较适合面向非洲、欧美的用户业务需求,也适合追求速度快又需要冷门的朋友。justg的俄罗斯VPS云服务器位于莫斯科机房,到美国和中国速度都非常不错,到欧洲的平均延迟时间为40毫秒,...

火数云-618限时活动,国内云服务器大连3折,限量50台,九江7折 限量30台!

官方网站:点击访问火数云活动官网活动方案:CPU内存硬盘带宽流量架构IP机房价格购买地址4核4G50G 高效云盘20Mbps独享不限openstack1个九江287元/月立即抢购4核8G50G 高效云盘20Mbps独享不限openstack1个九江329元/月立即抢购2核2G50G 高效云盘5Mbps独享不限openstack1个大连15.9元/月立即抢购2核4G50G 高效云盘5Mbps独享不限...

小欢互联19元/月起, 即日起至10月底 美国CERA 促销活动 美国/香港八折

小欢互联成立于2019年10月,主打海外高性价比云服务器、CDN和虚拟主机服务。近期上线了自营美国CERA机房高速VPS,进行促销活动,为客户奉上美国/香港八折优惠码:Xxc1mtLB优惠码适用于美国CERA一区/二区以及香港一区/二区优惠时间:即日起至10月底优惠码可无限次使用,且续费同价!官网:https://idc.xh-ws.com购买地址:美国CERA一区:https://idc.xh-...

androidhttpclient为你推荐
自动识别查询快递单号查看单号怎么知道是那个快递公司的eagleeye电脑进程中出现Eaglesvr这种程序,据说是一种蠕虫病毒。。。怎样杀掉?腾讯年终奖腾讯工作怎么样搜索引擎的概念什么是搜索引擎?搜索引擎是如何工作的?网络电话永久免费打有没有永久免费打电话的网络电话啊?腾讯技术腾讯是什么东西?文本框透明html怎么把这个文本框变为透明?数据库界面如何创建数据库监控插件千里眼监控软件怎么使用啊?汤不热福利汤不燥热的??
59.99美元 抢票工具 国外php空间 debian7 最好看的qq空间 中国智能物流骨干网 165邮箱 北京双线机房 秒杀预告 中国电信测网速 南通服务器 华为云盘 视频服务器是什么 免费个人网页 国外网页代理 google搜索打不开 中美互联网论坛 主机之家 56折扣网 文件服务器硬件配置 更多