如果有多个,Axios 只返回最后一个“set-cookie”

Rah*_*eel 9 iis cookies react-native axios

我在我的 react-native 应用程序中使用 axios 来调用 rest api。响应 api 调用,服务器返回多个“set-cookie”标头。但是 axios 只返回最后一个。

在 Postman 中尝试了相同的 API,它按预期返回 4 个“set-cookie”标头。在 axios 中,它总是最后一个

我已经做好了 axios.defaults.withCredentials = true;

我也试过在请求配置中包含它,就像这样......

axios.request( {
...otherConfig,
withCredentials: true
})
Run Code Online (Sandbox Code Playgroud)

如果我这样做...

axios.request({
            url: 'https://myurl.mydomain',
            method: 'post',
            headers: { 'Content-Type': 'application/json' },
            data: JSON.stringify(body),
            withCredentials: true,
        }).then(response => {
            console.log(response.headers['set-cookie'])
        });
Run Code Online (Sandbox Code Playgroud)

我希望上面的 console.log() 写出类似的东西

set-cookie: ["lang=AR; expires=somedate; path=/",
            ".ASPXAUTH=authtoken-value; expires=somedate; path=/",
            "OtherCookie1=111; expires=Tue, 21-May-2019 19:59:59 GMT; path=/"]
            "OtherCookie2=222; expires=Tue, 21-May-2019 19:59:59 GMT; path=/"]
Run Code Online (Sandbox Code Playgroud)

pie*_*tom 1

我在 NodeJS v18 中遇到了同样的问题,但没有找到解决方案。

使用本机fetchAPI 似乎可以正常工作:

  const response = await fetch(your_url);
  const cookie = console.log(response.headers.get('set-cookie'));
Run Code Online (Sandbox Code Playgroud)

在 NodeJS v18 中,我得到一个字符串,它是不同字符串的串联,但我也收到一条警告消息,因为 Fetch API 是一项实验性功能......

在线阅读似乎在浏览器中可能会返回一组不同的“Set-Cookie”。希望它能帮助其他人