GET 请求 Tomcat 经理

GET request Tomcat Manager

我正在尝试将应用程序远程部署到 Tomcat。为此,我需要执行以下 GET 请求:

http://localhost:8080/manager/text/deploy?path=/client-001&war=file:C:/.DS/tmp/client-001.war

我用我的 Java 代码来做:

String url = "http://localhost:8080/manager/text/deploy?path=/client-001&war=file:C:/.DS/tmp/client-001.war";
HttpClient client = HttpClientBuilder.create().build();
HttpGet request;
try {
      request = new HttpGet(url);
      request.addHeader(BasicScheme.authenticate(
      new UsernamePasswordCredentials("test", "test"),
                  "UTF-8", false));

      HttpResponse response = client.execute(request);
      BufferedReader rd = new BufferedReader(
                    new InputStreamReader(response.getEntity().getContent()));

      StringBuffer result = new StringBuffer();
      String line = "";
      while ((line = rd.readLine()) != null) {
            result.append(line);
      }

      System.err.println(result.toString());
} catch (Exception e){
      e.printStackTrace();
}

但是我得到了 403,即使我已经通过了我的凭据。

我做错了什么?

所以我发现了问题所在。

1) 我不需要将凭据传递给 Header,我只需要将 url 从 localhost:8080 更改为 test:test@localhost:8080

2) 我的用户 test 具有角色 manager-gui,要使 GET 工作,它需要角色 manager-script