HttpClient使用SESSIONID模拟用户发送请求
2015-05-20 16:54
357 查看
使用HttpClient版本 4.2.5
准备一已登录用户的sessionid:
转http://huangqiqing123.iteye.com/blog/2054490
准备一已登录用户的sessionid:
public static void main(String[] args) { String url = "http://10.10.10.90/urcweb/api/http.do?method=get_im_info"; Map<String,String> header = new HashMap<String,String>(); header.put("Cookie", "JSESSIONID=C1A34A2EC4C9423BB460E6F7005CA81E"); System.out.println(httpGet(url,null,header)); } /** * 发送 get 请求 * @param url * @param encode * @param headers * @return */ public static String httpGet(String url,String encode,Map<String,String> headers){ if(encode == null){ encode = "utf-8"; } String content = null; DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); //设置 header Header headerss[] = buildHeader(headers); if(headerss != null && headerss.length > 0){ httpGet.setHeaders(headerss); } HttpResponse http_response; try { http_response = httpclient.execute(httpGet); HttpEntity entity = http_response.getEntity(); content = EntityUtils.toString(entity, encode); } catch (Exception e) { e.printStackTrace(); }finally { httpGet.releaseConnection(); } return content; } /** * 组装请求头 * @param params * @return */ public static Header[] buildHeader(Map<String,String> params){ Header[] headers = null; if(params != null && params.size() > 0){ headers = new BasicHeader[params.size()]; int i = 0; for (Map.Entry<String, String> entry:params.entrySet()) { headers[i] = new BasicHeader(entry.getKey(),entry.getValue()); i++; } } return headers; }
转http://huangqiqing123.iteye.com/blog/2054490
相关文章推荐
- HttpClient使用SESSIONID模拟用户发送请求
- HttpClient使用SESSIONID模拟用户发送请求
- HttpClient使用SESSIONID模拟用户发送请求
- android_30_使用HttpClient发送Get和Post请求
- 使用C#发送Http 请求实现模拟登陆
- Android 通过httpclient请求web服务器,并解决用户登录session保持
- HttpComponent-HttpClient使用-发送Post请求
- 使用 HttpWebRequest 发送模拟 POST 请求
- 使用C#发送Http 请求实现模拟登陆(以博客园为例)
- 使用C#发送Http 请求实现模拟登陆(以博客园为例)
- 使用firefox插件httperrequest,模拟发送及接收Json请求
- 使用java程序模拟页面发送http的post请求
- 使用firefox插件httperrequest,模拟发送及接收Json请求 【转】
- 使用firefox插件httperrequest,模拟发送及接收Json请求
- Android 通过httpclient请求web服务器,并解决用户登录session保持
- 【实战】(二)android模拟qq登录(apache的httpClient发送get和post请求)
- 如何使用火狐下的两款接口测试工具RESTClient和HttpRequester发送post请求
- HttpClient使用之模拟登录人人网(Post请求)
- HttpURLConnection类 与HttpClient模拟向服务器发送请求
- 如何使用火狐下的两款接口测试工具RESTClient和HttpRequester发送post请求