private static string Sendpost (string url, namevaluepair[] params) {
HttpClient client = new HttpClient ();
Request timed out
Client.getparams (). Setparameter (Coreconnectionpnames.connection_timeout, 15000);
Read timeout
Client.getparams (). Setparameter (Coreconnectionpnames.so_timeout, 30000);
Demo login Page
Postmethod post = new Postmethod (URL);
Post.setrequestbody (params);
if (cookie = null && cookies.length > 0) {
Client.getstate (). addcookies (cookies);
}
try {
Client.executemethod (POST);
} catch (Exception e) {
E.printstacktrace ();
}
if (post.getstatuscode () = = 200) {
StringBuffer SBF = new StringBuffer ();
BufferedReader reader = null;
try {
InputStream InputStream = Post.getresponsebodyasstream ();
reader = new BufferedReader (new InputStreamReader (InputStream));
String line = null;
while (line = Reader.readline ()) = null) {
Sbf.append (line);
}
View cookie Information
cookies = Client.getstate (). GetCookies ();
return sbf.tostring ();
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (reader! = null) {
try {
Reader.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
}
}
Post.releaseconnection ();
return null;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java uses HTTP emulation form submission