Unirest将上一个请求的cookie带到下一个请求中
开发中,在后台模拟接口请求,常常需要将第一个登录接口的Cookie保留下来,掉用第二个接口的时候,需要把这个Cookie带过去,我们这次以Unirest为例,Unirest它默认是不会将上一个请求的Cookie带到下一个请求的,我们需要做如下设置。
CookieStore cookieStore = new org.apache.http.impl.client.BasicCookieStore();
Unirest.setHttpClient(org.apache.http.impl.client.HttpClients.custom().setDefaultCookieStore(cookieStore).build());
写个例子:
CookieStore cookieStore = new org.apache.http.impl.client.BasicCookieStore(); Unirest.setHttpClient(org.apache.http.impl.client.HttpClients.custom().setDefaultCookieStore(cookieStore).build()); Unirest.post("http://www.xxx.com/login.do") .field("username", username) .field("userpass", "123456") .field("action", "login") .asString(); Unirest.post("http://www.xxx.com/index.do") .field("name", username) .asString();
正在加载评论...
相关文章
- mybatis的xml中查单表和单表关联表的查询对比
- 新建springboot项目,springboot启动就结束,sprin...
- list.stream()前优雅的判断null
- @PostConstruct项目启动时执行该方法,即spring容...
- 手动触发shiro的doGetAuthorizationInfo方法的三种...
- 制作bat文件一键快捷替换指定.properties配置文件
- Java 配置@RequestMapping的produces参数值列表
- 通过https访问网页,request.getScheme()获取到的...
- Java利用正则表达式修改图片地址的域名,只修改域...
栏目列表
推荐阅读
- java的StringEscapeUtils转义与反转义
- Mybatis的foreach事列,如何获取foreach的index值
- errcode: 40001, errmsg: invalid credential, access_token is invalid or not latest rid: 5f6981c2-6cc9cb20-6833977a
- Java Ehcache缓存的timeToIdleSeconds和timeToLiveSeconds区别
- Java四种线程池newCachedThreadPool,newFixedThreadPool,newScheduledThreadPool,newSingleThreadExecutor
- tomcat启动maven工程报错-Updating status for Tomcat v7.0 Server at localhost...
- Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String'
- 服务器侦听端口 netstat -na 命令详解
- Java后台获取当前访问客户端的真实IP地址(外网或内网地址)
- java发送http的get、post请求
- StringSubstitutor替换占位符,处理SQL参数
- java拦截器HandlerInterceptor的preHandle、postHandle与afterCompletion三个方法
- com.googlecode.aviator.AviatorEvaluator规则引擎用法
- java中Session缓存和Cache缓存的区别
- Java8对象集合转List<Integer>id集合,转List<String>name集合,List<Class>对象集合
- Java导出excel利用jxls合并单元格jx:mergeCells实现表格嵌套技术
- 利用ObjectMapper,将json数组转List<Map<String,Object>>
- java图片文件base64流之间的互转帮助类源码下载
- java的DES加密解密辅助类
- ERROR ParametersInterceptor Developer Notification (set struts.devMode to false to disable this message)