简体   繁体   English

HttpClient Post请求URL问题,Java没有变化

[英]Issue with HttpClient Post request URL, no changes in Java

I am facing issue with HttpClient post request URL issue where I have generic method which is used throughout the application. 我面临HttpClient发布请求URL问题,我在整个应用程序中使用泛型方法。 We have total 7 projects running on single tomcat instance on same port. 我们在同一个端口上的单个tomcat实例上运行了7个项目。 We have one generic controller from where we are doing POST/GET calls. 我们有一个通用控制器来进行POST / GET调用。 Below is the POST request method: 以下是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 );
}

This is the URL which I am passing in postRequest method: ../application2/service/ 这是我在postRequest方法中传递的URL: ../ application2 / services /

Output: http://localhost:8080/application1../application2/service/ 输出: http:// localhost:8080 / application1 ../application2 / service /

I expect that URL should be like: http://localhost:8080/application2/service/ 我希望URL应该像: http:// localhost:8080 / application2 / service /

Any help is appreciated. 任何帮助表示赞赏。

You are passing wrong parameters. 你传递错误的参数。

Instead of adding: ../application2/service/ 而不是添加: ../ application2 / service /

Add this: /../application2/service/ 添加: /../application2/service/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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