=======================HttpClient3 属性设置========================
harbingerHttpClient client = new HttpClient();
HttpConnectionManagerParams cmp = HttpConnectionManager().getParams();
cmp.tConnectionTimeout(5000);//http连接超时
cmp.tSoTimeout(5000);//读数据超时
=======================HttpClient3 Post========================
PostMethod post = new PostMethod(url);
NameValuePair name$ = new NameValuePair("UrID","19104221");
NameValuePair authenticator$ = new NameValuePair("Authenticator",authenticator);
NameValuePair[] paramsPair = {name$,authenticator$};
post.addParameters(paramsPair);
英文翻译在线
schint stateCode = uteMethod(post);
//TODO 处理响应
//post.abort();
((HttpConnectionManager()).shutdown();
=======================HttpClient3 Get========================
GetMethod get = new GetMethod(url)
HttpMethodParams params = new HttpMethodParams();
params.tParameter("UrID", "99999005");
params.tParameter("Action", "Login");
get.tParams(params);
int statusCode = uteMethod(get);
//TODO 处理响应
//get.abort();
((HttpConnectionManager()).shutdown();
========================HttpClient4属性设置===============================
DefaultHttpClient httpclient = new DefaultHttpClient();
//模拟浏览器,解决一些服务器程序只允许浏览器访问的问题
//httpclient.tHttpRequestRetryHandler(requestRetryHandler);//请求重试Handler
//httpclient.tRedirectHandler();//重定向的处理(默认的DefaultRedirectHandler能够支持get,head自动重定向)
if(responInterceptor!=null)
httpclient.addResponInterceptor(responInterceptor);//响应拦截器
if(requestInterceptor!=null)
httpclient.addRequestInterceptor(requestInterceptor);//请求拦截器
========================HttpClient4 Get===============================
List<NameValuePair> qparams = getParamsList(params);
if (qparams != null && qparams.size() > 0) {
chart = (chart == null ? CHARSET_GBK : chart);
perverance
String formatParams = URLEncodedUtils.format(qparams, chart);
url = (url.indexOf("?")) < 0 ? (url + "?" + formatParams) : (url
.substring(0, url.index
Of("?") + 1) + formatParams);
}
DefaultHttpClient httpClient = getDefaultHttpClient();
HttpGet hg = new HttpGet(url);男士穿衣打扮
String respon = ute(hg,new BasicResponHandler());//BasicResponHandler控制响应结果为String
//TODO 处理响应
lookforwardtohg.abort();
va读音
httpClient=null;
========================HttpClient4 Post===============================
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(getParamsList(params), chart);
新东方英语暑假班DefaultHttpClient httpClient = getDefaultHttpClient();
HttpPost hp = new HttpPost(url);
if(formEntity!=null)
hp.tEntity(formEntity);
//TODO 处理响应
hg.abort();
httpClient=null;
//Map结构的参数转为NameValuePair列表
protected List<NameValuePair> getParamsList(Map<String, String> paramsMap) {itu
if (paramsMap == null || paramsMap.size() == 0) {
etn
return null;
}
List<NameValuePair> params = new ArrayList<NameValuePair>();
for (Map.Entry<String, String> map : Set()) {
params.add(new Key(), Value()));
}
return params;
}