• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

unable to login to a website. tried both httpclient and defaulthttpclient

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have used org.apache.commons.httpclient.HttpClient for the first one and org.apache.http.impl.client.DefaultHttpClient for the second. for both codes i'm getting response codes 200 ok. it is happening even when i remove username n pwd fields. So i'm not logging in...

1) HttpClient client = new HttpClient();
GetMethod get = new GetMethod("https://control.akamai.com");
System.out.println(client.executeMethod(get));

System.out.println("now login");

PostMethod method;
method = new PostMethod("https://control.akamai.com/EdgeAuth/login.jsp?");
method.addParameter("username", "akshay");
method.addParameter("password", "akshay");
System.out.println(client.executeMethod(method));


2) DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://control.akamai.com");

httpclient.getParams().setParameter(
HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler());

HttpResponse response;
try {

response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
entity.consumeContent();
}
System.out.println(response.getStatusLine());

System.out.println("Initial set of cookies:");
List<Cookie> cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("- " + cookies.get(i).toString());
}
}

HttpPost httpost = new HttpPost
("https://control.akamai.com/EdgeAuth/login.jsp?");
httpclient.getCookieStore().clear();

List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("username","akshay"));
nvps.add(new BasicNameValuePair("password","akshay"));

httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

response = httpclient.execute(httpost);
entity = response.getEntity();
if (entity != null) {
entity.consumeContent();
}

System.out.println(response.getStatusLine());

System.out.println("Post logon cookies:");
cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("- " + cookies.get(i).toString());
}
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
Sheriff
Posts: 22802
131
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tags. Your code will be much easier to read. Please remember to keep your indentation when you add the code tags.
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic