JAVA后台模拟登录一个网站,获得一定权限后进一步操作。

所用的工具:

Apache HttpComponents client 4.3版本

以下为代码:

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils; public class SimpleClient { public void test() throws Exception {
HttpGet httpget = null;
try { CloseableHttpClient httpclient = HttpClientBuilder.create().build(); httpget = new HttpGet("www.baidu.com");
//HttpGet httpget = new HttpGet(urlWithParams);
//配置请求的超时设置
/* RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(50)
.setConnectTimeout(50)
.setSocketTimeout(50)
.build();
httpget.setConfig(requestConfig);*/
CloseableHttpResponse response = httpclient.execute(httpget);
System.out.println("StatusCode -> " + response.getStatusLine().getStatusCode()); String set_cookie = response.getFirstHeader("Set-Cookie").getValue(); //打印Cookie值
System.out.println(set_cookie.substring(0,set_cookie.indexOf(";")));
HttpEntity entity = response.getEntity();
String jsonStr = EntityUtils.toString(entity);//, "utf-8");
System.out.println(jsonStr);
httpget.releaseConnection(); } catch (Exception e) {
e.printStackTrace();
} finally {
httpget.releaseConnection();
}
}
}

最新文章

  1. 【代码笔记】iOS-书架页面
  2. Effective C++ -----条款33:避免遮掩继承而来的名称
  3. [IIS][ASP.NET]“拒绝访问临时目录”的解决方法
  4. latex输入希腊字母
  5. leetcode course shedule
  6. unity3d学习笔记(十九)--ngui制作3d人物头顶的头像和血条
  7. MyEclipse 10官网下载地址以及破解方法
  8. Java异常(1)
  9. Android_常用控件及适配器
  10. MVC3 Razor @RenderSection
  11. office文件的预览
  12. json格式化和查看工具
  13. 十二生肖&天干地支
  14. VsCode放大缩小
  15. init_ir_技术实现篇
  16. CSRF重放共计详解
  17. 处女男学Android(七)---Android 应用资源之StateListDrawable
  18. 第三章 logstash - 输入插件之tcp与redis
  19. 学校网站UI设计分析
  20. X-Forwarded-For的一些理解

热门文章

  1. 【CF1025C】Plasticine zebra(模拟)
  2. vue.js源码学习分享(一)
  3. XSD(XML Schema Definition)学习笔记
  4. 新华三孟丹:NFV资源池实现中的技术探讨
  5. null相关
  6. Codeforces Gym 100203I I WIN 最大流
  7. Java1.8新特性——接口改动和Lambda表达式
  8. Flink起步安装和使用
  9. Codeforces Round #295 (Div. 1) C. Pluses everywhere
  10. SVG动画实践篇-无中生有的线条动画