logging into website using httpclient
Hi
I'm trying to log into wow armory from java so i can scrape some auctions. But i'm having problems logging in. My understanding is that i'm failing to send the cookies with the httpget after i succesfully logged in (i think ?? ). Anyways here is my test code, hope you can help.
It is runnable, just need the apache httpclient lib.
Code:
import java.util.ArrayList;
import java.util.List;
import org.apache.*;
public class ClientFormLogin {
public static void main(String[] args) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("https://eu.battle.net/login/en/");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("accountName", "concreteemail"));
nvps.add(new BasicNameValuePair("password", "concretepassword"));
// nvps.add(new BasicNameValuePair("submit",""));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
if (entity != null) { entity.consumeContent(); }
HttpGet httpget = new HttpGet("http://eu.wowarmory.com/auctionhouse/search.json");
// pretty sure this isn't right!
for (Cookie cookie : httpclient.getCookieStore().getCookies()) {
httpget.addHeader(cookie.getName(), cookie.getValue());
System.out.println(cookie);
}
// prints response
response = httpclient.execute(httpget);
entity = response.getEntity();
if (entity != null) {
long len = entity.getContentLength();
if (len != -1 && len < 2048) {
System.out.println(EntityUtils.toString(entity));
} else {
}
}
httpclient.getConnectionManager().shutdown();
}
}
thanks in advance.