Avatar of jchittoda1
jchittoda1Flag for India asked on

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

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());

Open in new window

Java

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
CEHJ

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
jchittoda1

Thanks CHEJ,

I was able to make the progress.

but having some issues in configuring the Proxy settings using HttpClient.

I do have some Proxyies with the credentials. I want to open a web page using those proxies. What configuration is required in HttpClient library to achieve the same.
CEHJ

I would actually use the java networking properties to configure the proxy as then there will be no need to recompile your code if the config changes

http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html
ASKER
jchittoda1

Here is the code for connecting the HttpClient via proxy.
HttpClient httpclient = new HttpClient();
HostConfiguration hostConfig = new HostConfiguration();
 
hostConfig.setProxy("192.168.2.4", 8080);
			initialState.setProxyCredentials(
		            new AuthScope("192.168.2.4", 8080, null),
		            new UsernamePasswordCredentials("UserId", "password"));
 
			
			
			httpclient.setHostConfiguration(hostConfig);

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
CEHJ

:-)

Good - but as i said you should do it in a way such that you don't need to recompile the code if and when the proxy settings change
ASKER
jchittoda1

No CEHJ,
I m using a text file to load the multiple proxies and using them randomly  :-)
So i can change proxies any time in the text file. Because of multiple proxies i can not use ur solution to define the proxies in the System.property.

BTW thanks for the "Charles" tool. Is there any other tool available in the market for the same web debugging?
CEHJ

>>Is there any other tool available in the market for the same web debugging?

The only ones i've used are ones in conjunction with IDEs or browsers. There are plugins for Firefox that show the http headers passed
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.