62,615
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://www.baidu.com/");
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add( new BasicNameValuePair("wd", "梅西") );
//formparams.add( new BasicNameValuePair("submit", "Search") );
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, Consts.UTF_8);
httpPost.setEntity(entity);
try {
// 把返回的数据写入文件
DataOutputStream out = new DataOutputStream( new FileOutputStream("F://post1.html") );
HttpResponse response = httpClient.execute(httpPost);
HttpEntity e = response.getEntity();
out.writeUTF( EntityUtils.toString(e) );
//System.out.println( EntityUtils.toString(e) );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}