有谁知道我在这里可能做错了什么?我在 tomcat-user.xml 中添加了用户名和密码,但仍然收到“401 Unauthorized”错误。
String url = "http://localhost:9080/manager/list";
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Authorization", "Basic " + userPass);
log.debug("executing request {}", httppost.getRequestLine());
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
BufferedReader rd = new BufferedReader(new InputStreamReader(entity.getContent()));
String line;
StringBuffer buffer = new StringBuffer();
while ((line = rd.readLine()) != null) {
buffer.append(line);
buffer.append('\n');
}
rd.close();