troubleshooting Question

How to load AIM(new screen name) page using HttpClient

Avatar of jchittoda1
jchittoda1Flag for India asked on
Java
7 Comments1 Solution675 ViewsLast Modified:
I am using HttpClient library to load the AIM page for creating new screen name. but creating screen name requires the cookies enabled. I also used some cookies code of HttpClient but i am unable to get to that page.

Please let me know how i can open and simulate the screen name creation ?

Thanks in advance
String strURL = "http://my.screenname.aol.com/_cqr/login/login.psp";
		
		HttpState initialState = new HttpState();
		
		HttpClient httpclient = new HttpClient();
		 httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
	     //httpclient.getParams().setParameter("http.protocol.single-cookie-header ", "true");
	     //httpclient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
	     httpclient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
	     httpclient.setState(initialState);
	     PostMethod httppost = new PostMethod(strURL);
	     httppost.setUseExpectHeader( false );
	     
	      //httppost.setFollowRedirects(true);
	     
	     
	      httppost.setStrictMode(false);
	     
	      httppost.setRequestHeader(new Header("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" ) );
	     
	      httppost.setRequestHeader( new Header( "accept", "*/*" ) );
	     
	      httppost.setRequestHeader( new Header( "accept-language", "en-us" ) );
	     
	      httppost.setRequestHeader( new Header( "accept-encoding", "gzip, deflate" ) );
	     
	      httppost.setRequestHeader( new Header( "connection", "Keep-Alive" ) );
	     
	      httppost.setRequestHeader( new Header( "cache-control", "no-cache" ) );
	     
	     
	   //"?sitedomain=www.aim.com&createSn=1&siteState=OrigUrl%3dhttp%253a%252f%252fwww%252eaim%252ecom%252f&icid=NavBadge_1_1"
	     httppost.addParameter("sitedomain", "www.aim.com");
	     httppost.addParameter("createSn", "1");
	     httppost.addParameter("siteState", "OrigUrl%3dhttp%253a%252f%252fwww%252eaim%252ecom%252f");
	     httppost.addParameter("icid", "NavBadge_1_1");
 
	     
	     
	     
	     
	        int result = httpclient.executeMethod(httppost);
	        
	        System.out.println("Response status code: " + result);
	        
	        Cookie[] cookies = httpclient.getState().getCookies();
	        
	        System.out.println("Present cookies: ");
	        for (int i = 0; i < cookies.length; i++) {
	            System.out.println(" - " + cookies[i].toExternalForm());
	        }
	        System.out.println(httppost.getResponseBodyAsString());
	        
	        Header[] arr = httppost.getResponseHeaders();
	        for (int i = 0; i < arr.length; i++) {
				System.out.println(arr[i].getName() + "=" + arr[i].getValue());
			}
	        httppost.releaseConnection();
	     
	        System.out.println("################################################");
	        
	        PostMethod httpget1 = new PostMethod(strURL);
	       // httpget1.setFollowRedirects(true);
	        httpget1.setRequestHeader("Cookie", cookies[0].toExternalForm() + ";" + cookies[1].toExternalForm());
//	        httpget1.addParameter("sitedomain", "www.aim.com");
//	        httpget1.addParameter("createSn", "1");
//	        httpget1.addParameter("siteState", "OrigUrl%3dhttp%253a%252f%252fwww%252eaim%252ecom%252f");
//	        httpget1.addParameter("icid", "NavBadge_1_1");
   
	        result = httpclient.executeMethod(httpget1);
	        
	        System.out.println("Response status code##: " + result);
	        System.out.println(httpget1.getResponseBodyAsString());
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros