【问题标题】:How to get response headers from RxJS's ajax?如何从 RxJS 的 ajax 中获取响应头?
【发布时间】:2019-09-16 16:47:49
【问题描述】:

我正在为面试系统创建新的前端。它的一些 API 端点已更新,因此获取分页信息不是问题,但旧的仍然在响应标头中包含分页数据。

附:我们正在使用 react、redux 和 redux-observable

RxJS 有如下调用:

ajax({ ...params }).pipe(
    map(response => { 
        // here I need to somehow get headers from ajax response
    }),
    catchError(errorResponse => {
        // return error
    })
)

【问题讨论】:

    标签: ajax rxjs redux-observable


    【解决方案1】:

    我一直在寻找相同的答案,看来有办法(见:https://stackblitz.com/edit/typescript-k2ggm2?file=index.ts):

    ajax({ ...params }).pipe(
        map(response => { 
            // here I need to somehow get headers from ajax response
            console.log(response.xhr.getAllResponseHeaders())
            console.log(response.xhr.getResponseHeader('pragma'))
        }),
        catchError(errorResponse => {
            // return error
        })
    )
    

    【讨论】:

    • 缺点是我们可能需要解析...在axios时代,fetch等等...好像有点奇怪
    • 刚刚发现,rxjs中有一个fromFetch,可能有headers可以更方便的访问
    猜你喜欢
    • 1970-01-01
    • 2020-08-10
    • 1970-01-01
    • 2017-05-14
    • 2017-09-15
    • 1970-01-01
    • 2013-05-28
    • 2012-10-02
    相关资源
    最近更新 更多