HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.test.com/login.aa");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name","zhangsan"));
nameValuePairs.add(new BasicNameValuePair("pwd","123456"));
try{
post.setEntity(new UrlEncodedFormEntity(nameValuePairs ));
HttpResponse response = client.execute(post);
System.out.println(EntityUtils.toString(response.getEntity()));
}catch(Exception e){
e.printStackTrace();
}
Http协议Post请求模拟
最新推荐文章于 2021-04-15 09:14:59 发布