HttpClient 警告:Cookie 被拒绝:非法域属性
我正在使用 HttpClient 最新版本 (4.x)。现在我正在尝试执行 GET 请求。 我刚刚发布了一个获取请求。
这是我的守则;
public class Poster {
static boolean routing1 = true, routing2 = true;
static int counter1 = 0, counter2 = 0;
DefaultHttpClient oHtp = null;
HttpGet oHGet = null;
HttpResponse oHRes = null;
private void test(String fullAddress) throws Exception {
oHtp = new DefaultHttpClient();
oHGet = new HttpGet(fullAddress);
HttpResponse response = oHtp.execute(oHGet);
System.out.print(response.getStatusLine());
HttpEntity entity = response.getEntity();
if (entity != null) {
entity = new BufferedHttpEntity(entity);
// System.out.println(EntityUtils.toString(entity));
System.out.print("\t entity is retrieved... ");
}
oHtp.getConnectionManager().shutdown();
}
}
我只是很好地执行它。 第一个是
new Poster().test("http://123.xl.co.id/profile.php");
,第二个是
new Poster().test("http://goklik.co.id/");
你,只有第二个......我收到了这个错误消息;
2011 年 9 月 18 日上午 10:11:30 org.apache.http.client.protocol.ResponseProcessCookies processCookies 警告:Cookie 被拒绝:“[版本:0][名称:CookiePst][值: 0149=xwGHF7HYDHLHQ84Isp/eSy9vu+Xq6cT12wxg1A==][域名: .mcore.com][路径:/][到期日:Sun Sep 18 10:38:59 ICT 2011]”。非法 域属性“mcore.com”。来源域名:“goklik.co.id”
我发现这里涉及到Cookie。但我不明白警告是什么意思。而且我也不知道如何解决它(Cookie 没有被拒绝)。希望有一点光明可以让我的思绪从你们身上消失......:D
I'm using HttpClient latest version (4.x). And right now I'm trying to do A GET Request.
I just posting a Get request.
This is my Code;
public class Poster {
static boolean routing1 = true, routing2 = true;
static int counter1 = 0, counter2 = 0;
DefaultHttpClient oHtp = null;
HttpGet oHGet = null;
HttpResponse oHRes = null;
private void test(String fullAddress) throws Exception {
oHtp = new DefaultHttpClient();
oHGet = new HttpGet(fullAddress);
HttpResponse response = oHtp.execute(oHGet);
System.out.print(response.getStatusLine());
HttpEntity entity = response.getEntity();
if (entity != null) {
entity = new BufferedHttpEntity(entity);
// System.out.println(EntityUtils.toString(entity));
System.out.print("\t entity is retrieved... ");
}
oHtp.getConnectionManager().shutdown();
}
}
I just execute it nicely.
First is
new Poster().test("http://123.xl.co.id/profile.php");
and second is
new Poster().test("http://goklik.co.id/");
ya, And Only the Second one.... I got this The error message;
Sep 18, 2011 10:11:30 AM
org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Cookie rejected: "[version: 0][name: CookiePst][value:
0149=xwGHF7HYDHLHQ84Isp/eSy9vu+Xq6cT12wxg1A==][domain:
.mcore.com][path: /][expiry: Sun Sep 18 10:38:59 ICT 2011]". Illegal
domain attribute "mcore.com". Domain of origin: "goklik.co.id"
I realized that the Cookie is involved here. But I don't understand what the Warning means. And I also don't know how to solve it (Cookie not being rejected). Hope there is a bit of light to clear my mind from you guys.... :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
也许为时已晚,但我遇到了同样的问题,并且找到了一些可以帮助我解决问题的方法,只需设置 Cookie 策略 与浏览器兼容性:
以下是可能的值:
Maybe it's too late, but I had the same problem and I've found something that helped me work it out, just set the Cookie Policy to Browser Compability:
Here are the possible values:
你无法“修复”它。该网站正在尝试设置一个不允许设置的 cookie,并且您正在使用的 apache 客户端库正在告诉您这一点。
当域名为
goklik.co.id
时,它尝试为mcore.com
设置 cookieYou can't "fix" it. The site is trying to set a cookie it's not allowed to set and the apache client library you're using is telling you about it.
It's trying to set a cookie for
mcore.com
when the domain isgoklik.co.id
在
httpclient
4.3 之前,同一页面中的这个答案很酷。但是自
httpclient
4.3以来,API似乎发生了很大变化,以下代码可以工作:Before
httpclient
4.3, this answer in the same page is cool.But since
httpclient
4.3, API seems changed a lot, following code would work:我正在使用 http 客户端 4.5.2,这是设置 cookie 规范来轻松解决我的问题。如何实例化客户端的示例:
I am using http client 4.5.2 and this is set cookie spec to easy solved my problem. The example of how instantiate client:
以下是在 v4.5.x(4.5.6 now)中抑制警告的最简单方法:
Here is the simplest way to suppress the warning in v4.5.x (4.5.6 right now) :
只是想改进埃里克的答案,因为它不能直接解决我的情况,但将 CookieSpecs 更改为 IGNORE_COOKIES 可以解决我的问题。
因为在我的 HttpClient 4.5 版本中 CookieSpecs.BROWSER_COMPATIBILITY 已经被折旧。
Just want to improve Eric's answer, as it doesnt directly solve my scenario but changing CookieSpecs to IGNORE_COOKIES solves my problem.
Because in my version of HttpClient 4.5 CookieSpecs.BROWSER_COMPATIBILITY is already depreciated.
如果您不需要处理 cookie,您可以使用 org.apache.http.impl.cookie.IgnoreSpecProvider 或 org.apache.http.impl.cookie.IgnoreSpec 禁用它。 /code> 取决于您使用的 API。在
HttpClientBuilder
上调用disableCookieManagement()
是不够的If you don't need to process cookies you can simply disable it, with
org.apache.http.impl.cookie.IgnoreSpecProvider
ororg.apache.http.impl.cookie.IgnoreSpec
depending on what API you use. CallingdisableCookieManagement()
onHttpClientBuilder
is not enough