jchittoda1
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
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());
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html
ASKER
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);
:-)
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
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
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?
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?
>>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
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
ASKER
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.