其他分享
首页 > 其他分享> > httpClient设置cookie不起作用

httpClient设置cookie不起作用

作者:互联网

被httpclient恶心到了,搞了半天终于解决了

BasicCookieStore cookies = new BasicCookieStore();
cookies.addCookie(new BasicClientCookie("userId", this.userId));
HttpClients.custom()
.setDefaultCookieStore(cookies)//设置Cookie
.setDefaultHeaders(transferMapToHeaderArray(headers))//设置Header
.build();
这样会导致设置的cookie不起作用,原因是
BasicClientCookie有一个domain参数是设置起作用的域名,不设置默认所有域名不起作用
将上面的改成这样就可以了
BasicClientCookie bc1 = new BasicClientCookie("userId", this.userId);
bc1.setDomain("api.io.mi.com");
 

标签:cookies,BasicClientCookie,不起作用,userId,cookie,设置,new,httpClient
来源: https://www.cnblogs.com/ashScc/p/15467946.html