Lotus Notes/Domino - 如何在 Angular 应用程序中获取 'Content-Range'

Lotus Notes/Domino - How to get 'Content-Range' in Angular app

我创建了一个 Angular 应用程序,我正在使用 HttpClient 从 IBM/Notes Domino 服务器获取数据。我正在使用 Domino 数据服务访问数据库中的数据,其中 URL 像这样 /{database}/api/data/collections/name/{viewname}。 数据从服务器返回时很好,我可以使用 Chrome DevTools 的“网络”选项卡看到这一点。

在服务器的响应中,我可以看到 Content-Range header 但在我的 Angular 应用程序中我无法访问它!

在 Angular 应用程序中,我使用它来观察服务器的响应

this.httpClient.get<any>('/{database}/api/data/collections/name/{viewname}', {observe: 'response'})
    .subscribe(
        resp => {
        console.log(resp);
        }
    );

在控制台中,我可以看到 headers:headers: Map(3) {"content-type" => Array(1), "cache-control" => Array(1), "content-length" => Array(1)}

我在 Domino 网站规则的自定义 header 中添加了 Access-Control-Allow-Headers,值为 Content-Range

有谁知道我怎样才能到达 Angular 中的 Content-Range header?

您似乎没有将 Content-range 添加到 server-side 上公开的 headers。

也许你可以试试这个: [EnableCors("<a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>", "<em>", "</em>", exposedHeaders: "Content-Range")]

您需要将后端设置为 return HTTP header,Access-Control-Expose-Headers,值为 Content-Range。即,完整:Access-Control-Expose-Headers: Content-Range.

然后在 Angular 中,您可以通过执行 .headers.get():

检索 headers

例如

this.httpClient.get<any>('/{database}/api/data/collections/name/{viewname}', {observe: 'response'})
    .subscribe(
        resp => {
           console.log(resp);
           console.log(resp.headers.get('Content-Range'));
        }
    );

所以在其他人的帮助下我有了答案!

为了帮助其他人,这里是您需要遵循的解决方案,以使其在 Domino 服务器上运行。

在 Domino Director 中,转至 Web -> Internet 站点。在网站规则文档中 规则 (headers):Custom headers 字段中输入以下内容:

然后在服务器的 Notes.ini 文件中,您需要以下行:

HTTPAdditionalRespHeader=HTTPAdditionalRespHeader=Access-Control-Allow-Credentials:true

重新启动 Domino 服务器,很快它就可以工作了!