【问题标题】:Issue with HttpClient Post request URL, no changes in JavaHttpClient Post 请求 URL 的问题,Java 中没有变化
【发布时间】:2019-02-20 04:32:00
【问题描述】:

我面临 HttpClient 发布请求 URL 问题,我有在整个应用程序中使用的通用方法。我们总共有 7 个项目在同一端口上的单个 tomcat 实例上运行。我们有一个通用控制器,用于进行 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/

我希望 URL 应该是:http://localhost:8080/application2/service/

感谢任何帮助。

【问题讨论】:

    标签: java spring-mvc url post httpclient


    【解决方案1】:

    您传递了错误的参数。

    而不是添加: ../application2/service/

    添加这个: /../application2/service/

    【讨论】:

      猜你喜欢
      • 2011-11-01
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-14
      相关资源
      最近更新 更多