[英]Http request to get response from other web application
我有 2 个不同的域,有 2 个不同的 java 基于 web 应用程序。 第一个叫做 X,第二个叫做 Y我实际上想要做的是:
试图从数据库 Y 中获取客户信用信息,通过 HTTP 请求到我的第二个 web 应用程序。 我怎样才能做到这一点?
下面是使用 apache HttpClient 的 rest 客户端,
String url = {Y Service URL};
URIBuilder uriBuilder = new URIBuilder(url);
URI uri = uriBuilder.build();
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(uri);
httpResponse = httpClient.execute(httpGet);
int statusCode = httpResponse.getStatusLine().getStatusCode();
HttpEntity entity = httpResponse.getEntity(); // Response body of Y service.
替代方案:Java 9 http 客户端,Spring restTemplate。 Java 9 http 客户端: https://www.baeldung.com/java-9-http-client
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.