andr o id开发 http工具类public static HttpClient httpClient=new DefaultHttpClient();public static final String BASE_URL=
*get请求
*@param url
*发送请求的URL
*@r eturn服务器响应字符串
*@throw s Exc eptionpublic static String doGet(String url) throws Exc eption{//创建Http Get对象。
HttpGet get=new HttpGet(url);
//发送GET请求
HttpRes pons e httpRes pons e=httpClient.exec ute(get);//如果服务器成功地返回响应if(httpRespons e.getStatus Line().getStatus Code()==200) {//获取服务器响应字符串
HttpEnt ity entity=httpRe s p ons e.getEntity();
InputS tream c ontent=entity.getContent();return c onvertStreamTo String(c ontent);r eturn null;
*p os t请求
*@param url
*发送请求的URL
*@param params
*请求参数
*@r eturn服务器响应字符串
*@throw s Exc eptionpublic static String doPost(String url,Map String,String rawParams)throw s Exc eption{
//创建Http P o st对象。
HttpPost post=new HttpPost(url);
//如果传递参数个数比较多的话可以对传递的参数进行封装List NameValuePair params=new ArrayList NameValuePairfor(String key:rawParams.keySet()) {
//封装请求参数params.add(new BasicNameValuePair(key, rawParams.get(key)));//设置请求参数post.s etEntity(new UrlEnc odedFormEntity(params,utf-8));//发送P O ST请求
HttpRes pons e httpRes pons e=http Client.exec ute(po s t);
//如果服务器成功地返回响应if(httpRespons e.getStatus Line().getStatus Code()==200) {
//获取服务器响应字符串
HttpEnt ity entity=httpRe s p ons e.getEntity();
InputS tream c ontent=entity.getContent();
return c onvertStreamToString(c ontent);r eturn null;
*获取服务器的响应转换为字符串private static String convertStreamToString(InputStream is) {
BufferedReader reader=new BufferedReader(new InputStreamReader(is));StringBuilder sb=new StringBuilder();
String line=null;try{w hile((line=reader.readL ine()) !=null) {sb.append(line);
} catch(IOException e) {e.printStackTrac e();
}final ly{try{is.c lo s e();
} catch(IOException e) {e.printStackTrac e();return sb.toString();
阿里云国际版注册认证教程-免绑卡-免实名买服务器安全、便宜、可靠、良心,支持人民币充值,提供代理折扣简介SunthyCloud成立于2015年,是阿里云国际版正规战略级渠道商,也是阿里云国际版最大的分销商,专业为全球企业客户提供阿里云国际版开户注册、认证、充值等服务,通过SunthyCloud开通阿里云国际版只需要一个邮箱,不需要PayPal信用卡就可以帮你开通、充值、新购、续费阿里云国际版,服务...
ZJI是成立于2011年原Wordpress圈知名主机商—维翔主机,2018年9月更名为ZJI,主要提供香港、日本、美国独立服务器(自营/数据中心直营)租用及VDS、虚拟主机空间、域名注册业务。本月商家针对香港阿里云线路独立服务器提供月付立减270-400元优惠码,优惠后香港独立服务器(阿里云专线)E3或者E5 CPU,SSD硬盘,最低每月仅480元起。阿里一型CPU:Intel E5-2630L...
易探云产品限时秒杀&QQ音乐典藏活动正在进行中!购买易探云香港/美国云服务器送QQ音乐绿钻豪华版1年,价值180元,性价比超级高。目前,有四大核心福利产品推荐:福利一、香港云服务器1核1G2M,仅218元/年起(香港CN2线路,全球50ms以内);福利二、美国20G高防云服务器1核1G5M,仅336元/年起(美国BGP线路,自带20G防御);福利三、2G虚拟主机低至58.8元/年(更有免费...