【发布时间】: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