日期:2014-05-17 浏览次数:20780 次
// 构造HttpClient的实例
HttpClient httpClient = new HttpClient();
// 模仿用户进行表单提交
PostMethod authpost = new PostMethod("url路径");
authpost.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
// 模拟控件用户名和密码
NameValuePair userid = new NameValuePair("userName", "administrator");//控件名和值
NameValuePair password = new NameValuePair("password", "administrator");
authpost.setRequestBody(new NameValuePair[] { userid, password });
httpClient.executeMethod(authpost);
String message = authpost.getResponseBodyAsString();
System.out.println(message);