【问题标题】:Http request to get response from other web application [duplicate]从其他Web应用程序获取响应的Http请求[重复]
【发布时间】:2022-01-11 09:28:33
【问题描述】:

我有 2 个不同的域和 2 个不同的基于 Java 的 Web 应用程序。 第一个叫 X,第二个叫 Y 我真正想做的是:

尝试通过对我的第二个 Web 应用程序的 HTTP 请求从数据库 Y 中获取客户信用信息。 我该怎么做?

【问题讨论】:

    标签: java jsf web-applications httprequest


    【解决方案1】:

    下面是使用apache HttpClient的其余客户端,

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-14
      • 2019-10-22
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      • 1970-01-01
      • 2018-05-10
      相关资源
      最近更新 更多