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
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:You 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
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 enoughI am using http client 4.5.2 and this is set cookie spec to easy solved my problem. The example of how instantiate client:
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:
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.