Results 1 to 1 of 1
  1. #1
    brianfroelund is offline Member
    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    Question 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.

    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();        
        }
    }
    thanks in advance.
    Last edited by brianfroelund; 01-26-2011 at 06:31 PM.

Similar Threads

  1. httpClient API to Download a xls file.
    By mpahlenig in forum New To Java
    Replies: 1
    Last Post: 01-13-2010, 03:31 AM
  2. Using HttpClient
    By jdetloff in forum New To Java
    Replies: 4
    Last Post: 01-06-2010, 10:43 AM
  3. Using HttpClient with Eclipse
    By jdetloff in forum Eclipse
    Replies: 4
    Last Post: 01-06-2010, 09:47 AM
  4. Getting httpclient working with eclipse.
    By int80 in forum Eclipse
    Replies: 4
    Last Post: 03-31-2009, 01:17 PM
  5. How to download website (Get all link in website)
    By finalmem in forum Advanced Java
    Replies: 0
    Last Post: 11-12-2008, 08:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •