Hi All,
When use org.apache.http.impl.client.DefaultHttpClient to login appfuse,the
status shows that "Connection to http://localhost:8080 refused" which throws
from IOException.
How to use httpclient to login?
Please Hint,
Thank you very much,
Maker Su
//
HttpPost httpost = new HttpPost("http://localhost:8080/j_security_check");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("j_username", "user"));
nvps.add(new BasicNameValuePair("j_password", "user"));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
System.out.println("Login form post: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
System.out.println("Post logon 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());
}
}
httpclient.getConnectionManager().shutdown();