Issue with HttpClient Post request URL, no changes in Java

Ankit Jani :

I am facing issue with HttpClient post request URL issue where I have generic method which is used throughout the application. We have total 7 projects running on single tomcat instance on same port. We have one generic controller from where we are doing POST/GET calls. Below is the POST request method:

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/

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

I expect that URL should be like: http://localhost:8080/application2/service/

Any help is appreciated.

Aakash Patel :

You are passing wrong parameters.

Instead of adding: ../application2/service/

Add this: /../application2/service/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=109222&siteId=1