Public boolean uploadHttpClient (String path, Map <String, String> params) throws IOException {
// 1. Put the parameter into a list set. Each parameter is a NameValuePair object.
List <NameValuePair> paramPair = new ArrayList <NameValuePair> ();
If (params! = Null &&! Params. isEmpty ()){
For (Map. Entry <String, String> entry: params. entrySet ()){
ParamPair. add (new BasicNameValuePair (entry. getKey (), entry. getValue ()));
}
}
// 2. Create a request object. The parameter set is used as the construction parameter.
UrlEncodedFormEntity entity = new UrlEncodedFormEntity (paramPair, "UTF-8 ");
// 3. Create a post request and put the object in
HttpPost post = new HttpPost (path );
Post. setEntity (entity );
// 4. Create a request client and execute the request to obtain the corresponding
DefaultHttpClient client = new DefaultHttpClient ();
HttpResponse res = client.exe cute (post );
If (res. getStatusLine (). getStatusCode () = 200 ){
Return true;
}
Return false;
}
SLL or Https is used in the project. It is convenient to use this open-source project when using cookies. If it is not used, it is more efficient to directly operate the http protocol.
From: com360 Column