简体   繁体   中英

Tomcat manager connection through HttpClient

Does anyone know what I might be doing wrong here? I added the username and password to the tomcat-user.xml but I am still getting a "401 Unauthorized" error.

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

The answer depends on whether you're using Tomcat 5.5/6 or Tomcat 7.

Tomcat 7

You'll need to access the the listing with the following URL:

http://localhost:9080/manager/text/list

You'll need to configure tomcat-user.xml with a user that has the manager-script role.

Tomcat 5.5/6

You'll need to access the the listing with the following URL:

http://localhost:9080/manager/list

You'll need to configure tomcat-user.xml with a user that has the manager role.

Update

You may not be performing the Basic Auth step correctly. The username/pass might need to be base64 encoded. See the highest voted answer in this question: Http Basic Authentication in Java using HttpClient?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM