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();
适逢中国农历新年,RAKsmart也发布了2月促销活动,裸机云、云服务器、VPS主机全场7折优惠,新用户注册送10美元,独立服务器每天限量秒杀最低30.62美元/月起,美国洛杉矶/圣何塞、日本、香港站群服务器大量补货,1-10Gbps大带宽、高IO等特色服务器抄底价格,机器可选大陆优化、国际BGP、精品网及CN2等线路,感兴趣的朋友可以持续关注下。裸机云新品7折,秒杀产品5台/天优惠码:Bare-...
腾讯云双十一活动已于今天正式开启了,多重优惠享不停,首购服务器低至0.4折,比如1C2G5M轻量应用服务器仅48元/年起,2C4G8M也仅70元/年起;个人及企业用户还可以一键领取3500-7000元满减券,用于支付新购、续费、升级等各项账单;企业用户还可以以首年1年的价格注册.COM域名。活动页面:https://cloud.tencent.com/act/double11我们分享的信息仍然以秒...
一年一度的黑色星期五和网络星期一活动陆续到来,看到各大服务商都有发布促销活动。同时RAKsmart商家我们也是比较熟悉的,这次是继双十一活动之后的促销活动。在活动产品中基本上沿袭双11的活动策略,比如有提供云服务器七折优惠,站群服务器首月半价、还有新人赠送红包等活动。如果我们有需要RAKsmart商家VPS、云服务器、独立服务器等产品的可以看看他们家的活动。这次活动截止到11月30日。第一、限时限...