我面临HttpClient发布请求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 / services /
输出:http://localhost:8080/application1../application2/service/
我希望URL应该像:http://localhost:8080/application2/service/
任何帮助表示赞赏。
你传递错误的参数。
而不是添加:../ application2 / service /
添加:/../application2/service/