Results 1 to 1 of 1
- 01-26-2011, 02:55 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 1
- Rep Power
- 0
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.
thanks in advance.Java 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(); } }Last edited by brianfroelund; 01-26-2011 at 06:31 PM.
Similar Threads
-
httpClient API to Download a xls file.
By mpahlenig in forum New To JavaReplies: 1Last Post: 01-13-2010, 03:31 AM -
Using HttpClient
By jdetloff in forum New To JavaReplies: 4Last Post: 01-06-2010, 10:43 AM -
Using HttpClient with Eclipse
By jdetloff in forum EclipseReplies: 4Last Post: 01-06-2010, 09:47 AM -
Getting httpclient working with eclipse.
By int80 in forum EclipseReplies: 4Last Post: 03-31-2009, 01:17 PM -
How to download website (Get all link in website)
By finalmem in forum Advanced JavaReplies: 0Last Post: 11-12-2008, 08:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks