Http开发模块
来源:互联网 发布:启动mysql服务 编辑:程序博客网 时间:2024/05/29 05:12
package com.jxqx.httpget;import java.util.ArrayList;import java.util.List;import org.apache.http.HttpResponse;import org.apache.http.HttpStatus;import org.apache.http.client.HttpClient;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.conn.params.ConnManagerParams;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.message.BasicNameValuePair;import org.apache.http.params.BasicHttpParams;import org.apache.http.params.HttpConnectionParams;import org.apache.http.params.HttpParams;import org.apache.http.protocol.HTTP;import org.apache.http.util.EntityUtils;public class HttpUtils {public static String doGet(String url){String responseStr=null;try{HttpClient httpClient=new DefaultHttpClient();//设置Http Get请求HttpGet httpRequest=new HttpGet(url);//超时设置HttpParams params=new BasicHttpParams();//从连接池中获取连接的超时时间,设置为1秒ConnManagerParams.setTimeout(params, 1000);//连接服务器的超时时间。HttpConnectionParams.setConnectionTimeout(params, 3000);HttpConnectionParams.setSoTimeout(params, 5000);httpRequest.setParams(params);HttpResponse httpResponse=httpClient.execute(httpRequest);final int ret=httpResponse.getStatusLine().getStatusCode();if(ret==HttpStatus.SC_OK){responseStr=EntityUtils.toString(httpResponse.getEntity(),HTTP.UTF_8);}else{responseStr="出错了";}}catch(Exception e){e.printStackTrace();responseStr=e.getMessage();}return responseStr;}public static String dopost(String url){String responseStr=null;try{HttpClient httpClient=new DefaultHttpClient();HttpPost httpRequest=new HttpPost(url);HttpParams params=new BasicHttpParams();ConnManagerParams.setTimeout(params, 1000);HttpConnectionParams.setConnectionTimeout(params, 3000);HttpConnectionParams.setSoTimeout(params, 5000);httpRequest.setParams(params);List<BasicNameValuePair>paramsList=new ArrayList<BasicNameValuePair>();paramsList.add(new BasicNameValuePair("id","0206"));paramsList.add(new BasicNameValuePair("name","肖祥阔"));UrlEncodedFormEntity mUrlEncodedFormEntity=new UrlEncodedFormEntity(paramsList,HTTP.UTF_8);httpRequest.setEntity(mUrlEncodedFormEntity);HttpResponse httpResponse=httpClient.execute(httpRequest);final int ret=httpResponse.getStatusLine().getStatusCode();if(ret==HttpStatus.SC_OK){responseStr=EntityUtils.toString(httpResponse.getEntity(), HTTP.UTF_8);}else{responseStr="出错啦!";}}catch(Exception e){e.printStackTrace();responseStr=e.getMessage();}return responseStr;}}
0 0
- Nginx Http模块开发
- Nginx Http模块开发
- Http开发模块
- 开发http模块
- 开发一个HTTP过滤模块
- Nginx HTTP过滤模块开发
- 【Nginx】开发一个简单的HTTP模块
- 【Nginx】开发一个HTTP过滤模块
- nginx http 模块开发config原理
- Nginx基础. 开发HTTP过滤模块
- lua开发之--mysql和http模块
- nginx 开发简单的http模块
- nodejs开发——http模块
- vue开发公共模块封装(http)
- http模块
- http模块
- Nginx模块开发(5)————开发简单的HTTP过滤模块
- 淘宝开发:Nginx模块Nginx-Http-Footer-Filter
- 软件测试之 控制流图 圈复杂度 独立路径 测试用例
- 国外程序员推荐:每个程序员都应读的书
- TQ210移植minigui1.6.6
- 字符检测 cctype(ctype.h)
- git基本原理详解
- Http开发模块
- bat shell删除目录下文件
- 交换两个变量的值,不使用第三个变量的四种法方
- Python 上传服务并覆盖同名服务
- How Do I Route Audio to Speaker without using AudioSessionSetProperty?
- SSM框架——使用MyBatis Generator自动创建代码
- C# 图片的转换,一个简单的实例,没有特别的修饰,涉及线程
- guid 的javascript 生成方法
- Struts bean标签