Http协议Post请求模拟

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();
}

猜你喜欢

转载自zcw-java.iteye.com/blog/1495312