我面临着httpclient post-request-url问题,在这个问题上,我有一个在整个应用程序中使用的通用方法。我们在同一端口上的单个tomcat实例上总共运行了7个项目。我们有一个通用的控制器,可以从那里进行post/get调用。以下是POST请求方法:

public HttpResponse postRequest( final String URLString, final Map<String, String> requestHeader, final String requestData)
        throws ClientProtocolException, IOException {

    Utility.LOGGER.info(this.getClass().getName() + "==> Method : postRequest ==> Enter");

    String testServiceUrl = null;
    testServiceUrl = testApplicationInitializer.getConfigurationsByConfigTableName().get("APP_SERVER_URL") + "/application1";

    final HttpClient httpClient = HttpClientBuilder.create().build( );
    System.out.println("URL: ==> " + testServiceUrl + URLString);
    final HttpPost httpPost = new HttpPost(testServiceUrl + URLString );
    if (requestHeader != null && !requestHeader.isEmpty() ) {
        for (final Map.Entry<String, String> entry : requestHeader.entrySet() ) {
            httpPost.addHeader(entry.getKey(), entry.getValue() );
        }
    }

    Utility.LOGGER.info(this.getClass().getName() + "==> Method : postRequest ==> Exit");
    return httpClient.execute(httpPost );
}

这是我在postrequest方法中传递的url:../application2/service/
输出:http://localhost:8080/application1../application2/service/
我想网址应该是:http://localhost:8080/application2/service/
如有任何帮助,我们将不胜感激。

最佳答案

您传递了错误的参数。
而不是添加:../application2/service/
添加此:/../application2/service/

07-24 09:33