使用isomorphic-fetch获取响应头信息

3

我能够成功地获取到所有的正文数据,但是头部信息是空的。响应头中有一个访问令牌,我需要它来进行未来的请求。当我使用curl或postman时,我可以看到头部信息,但是使用isomorphic-fetch却得到了一个空的头部。

fetch(endpoint, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: data})
.then(checkStatus)
.then(response => response.headers ); // response.json() gets me body data

有人成功地使用isomorphic-fetch检索标题吗?

1个回答

3

我明白了。客户端并不是问题所在,当进行CORS时,自定义头需要额外的配置。问题出在服务器上,因为我的API缺少一行配置:

headers: :any,
expose:  ['access-token', 'expiry', 'token-type', 'uid', 'client'], # Was missing this line.
methods: [:get, :post, :put, :patch, :delete, :options, :head]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接