File file = new File("somefile.txt");
FileEntity entity = new FileEntity(file, "text/plain; charset=\"UTF-8\"");
HttpPost httppost = new HttpPost("http://localhost/action.do");
httppost.setEntity(entity); //各种Entity之FileEntity
List<NameValuePair>list=new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("name", name));
list.add(new BasicNameValuePair("pwd", pwd));
httpPost.setEntity(new UrlEncodedFormEntity(list,HTTP.UTF_8));//各种Entity之UrlEncodedFormEntity
MultipartEntity mpEntity = new MultipartEntity();
File file = new File(fileurl);
mpEntity.addPart("file", newFileBody(file));//可用于自制文件的上传
mpEntity.addPart("data", new StringBody(data, Charset.forName(org.apache.http.protocol.HTTP.UTF_8)));
httpPost.setEntity(mpEntity);//各种Entity之MultipartEntity
----------------------------------------------
httpPost = new HttpPost(url);
......
HttpResponse response = client.execute(httpPost);//参数为完整地址
host = new HttpHost(domain, 80, "http");
httpPost = new HttpPost(url);
......
response = client.execute(host, httpPost);//参数拼接为完整地址
httppost.setEntity(entity); //各种Entity之FileEntity
List<NameValuePair>list=new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("name", name));
list.add(new BasicNameValuePair("pwd", pwd));
httpPost.setEntity(new UrlEncodedFormEntity(list,HTTP.UTF_8));//各种Entity之UrlEncodedFormEntity
MultipartEntity mpEntity = new MultipartEntity();
File file = new File(fileurl);
mpEntity.addPart("file", newFileBody(file));//可用于自制文件的上传
mpEntity.addPart("data", new StringBody(data, Charset.forName(org.apache.http.protocol.HTTP.UTF_8)));
httpPost.setEntity(mpEntity);//各种Entity之MultipartEntity
----------------------------------------------
httpPost = new HttpPost(url);
......
HttpResponse response = client.execute(httpPost);//参数为完整地址
host = new HttpHost(domain, 80, "http");
httpPost = new HttpPost(url);
......
response = client.execute(host, httpPost);//参数拼接为完整地址