Commons-logging.jar and commons-codec.jar. The two bags don't have any error.
Httpclient 4.0 beta2
Code
Package com. testhttpclient;
Import java. Io. ioexception;
Import java. util. arraylist;
Import java. util. List;
Import org. Apache. http. httpentity;
Import org. Apache. http. httpresponse;
Import org. Apache. http. namevaluepair;
Import org. Apache. http. Client. httpclient;
Import org. Apache. http. Client. entity. urlencodedformentity;
Import org. Apache. http. Client. Methods. httpget;
Import org. Apache. http. Client. Methods. httppost;
Import org. Apache. http. Client. Params. clientpnames;
Import org. Apache. http. Client. Params. cookiepolicy;
// Import org. Apache. http. Client. Params. httpclientparams;
Import org. Apache. http. impl. Client. defaulthttpclient;
Import org. Apache. http. Message. basicnamevaluepair;
Import org. Apache. http. Protocol. HTTP;
Import org. Apache. http. util. entityutils;
Public class maintest {
Public static void main (string [] ARGs ){
String url = "";
Httpclient = new defaulthttpclient ();
// Httpclient. getparams (). setparameter (httpclientparams. cookie_policy, cookiepolicy. browser_compatibility );
Httpclient. getparams (). setparameter (clientpnames. cookie_policy, cookiepolicy. browser_compatibility );
// Get Method
Httpget = new httpget (URL );
Httpget. setheader ("Accept-language", "ZH-CN "); //
Try {
Httpresponse response = httpclient.exe cute (httpget );
Httpentity entity = response. getentity ();
String webcode = new string (entityutils. tostring (response. getentity (). getbytes ("ISO-8859-1"), "UTF-8"); // detailed analysis
If (entity! = NULL ){
Try {
Entity. consumecontent ();
} Catch (ioexception e ){
E. printstacktrace ();
}
}
} Catch (exception ex ){
Ex. printstacktrace ();
}
// POST method
Httppost = new httppost (URL );
Httppost. setheader ("","");
// Namevaluepair [] nvps = new namevaluepair [] {
// New basicnamevaluepair ("",""),
// New basicnamevaluepair ("","")//
//};
// Httppost. setentity (New urlencodedformentity (nvps, HTTP. utf_8 ));
List <namevaluepair> parameters = new arraylist <namevaluepair> ();
Parameters. Add (New basicnamevaluepair ("",""));//
Try {
Httppost. setentity (New urlencodedformentity (parameters, HTTP. utf_8 ));
Httpresponse response = httpclient.exe cute (httppost );
Httpentity entity = response. getentity ();
String webcode = entityutils. tostring (response. getentity ());
If (entity! = NULL ){
Try {
Entity. consumecontent ();
} Catch (ioexception e ){
E. printstacktrace ();
}
}
} Catch (exception ex ){
Ex. printstacktrace ();
}
}
}