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();
VoLLcloud LLC是一家成立于2020年12月互联网服务提供商企业,于2021年1月份投入云计算应用服务,为广大用户群体提供云服务平台,已经多个数据中心部署云计算中心,其中包括亚洲、美国、欧洲等地区,拥有自己的研发和技术服务团队。现七夕将至,VoLLcloud LLC 推出亚洲地区(香港)所有产品7折优惠,该产品为CMI线路,去程三网163,回程三网CMI线路,默认赠送 2G DDoS/C...
青云互联怎么样?青云互联是一家成立于2020年6月份的主机服务商,致力于为用户提供高性价比稳定快速的主机托管服务,目前提供有美国免费主机、香港主机、香港服务器、美国云服务器,让您的网站高速、稳定运行。目前,美国洛杉矶cn2弹性云限时七折,美国cera机房三网CN2gia回程 13.3元/月起,可选Windows/可自定义配置。点击进入:青云互联官网青云互联优惠码:七折优惠码:dVRKp2tP (续...
关于CYUN商家在之前有介绍过一次,CYUN是香港蓝米数据有限公司旗下的云计算服务品牌,和蓝米云、蓝米主机等同属该公司。商家主要是为个人开发者用户、中小型、大型企业用户提供一站式核心网络云端部署服务,促使用户云端部署化简为零,轻松快捷运用云计算。目前,CYUN主要运营美国、香港、台湾、日本、韩国CN2线路产品,包括云服务器、站群服务器和独立服务器等。这次看到CYUN夏季优惠活动发布了,依然是熟悉的...