gpt4 book ai didi

javascript - 响应 header 不可用于获取 'redirect: manual' 的请求

转载 作者:行者123 更新时间:2023-12-04 21:03:35 25 4
gpt4 key购买 nike

我在做

        console.log("navigating");
var rsp = await fetch(params.url, {
credentials: "include", redirect: "manual", mode: "cors"
});
console.log(rsp);
rsp.headers.forEach(console.log);

console.log(rsp.headers.get('Location'));
console.log(rsp.headers.get('location'));
以及来自 chrome devtools 的响应 header :
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:4400
Access-Control-Expose-Headers: Location
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 0
Date: Fri, 05 Oct 2018 12:48:21 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Location: http://localhost/test
Response 
body: (...)
bodyUsed: falseheaders:
Headers {}
ok: false
redirected: false
status: 0
statusText: ""
type: "opaqueredirect"
url: "..."

index.ts:161 null
index.ts:162 null
是否无法在重定向响应中获取响应 header ?

最佳答案

Is it not possible to get response headers out on redirect response?


不,这是不可能的。 Fetch 规范中的要求阻止了它。 manual 预期问题显示的内容重定向模式:暴露给前端 JS 的 headers 对象在响应 redirect: "manual" 时预计为空要求。
当请求设置 manual重定向模式,响应类型为 opaqueredirect .有关其影响的信息位于 https://developer.mozilla.org/en-US/docs/Web/API/Response/type :

opaqueredirect: The fetch request was made with redirect: "manual". The Response's status is 0, headers are empty, body is null and trailer is empty.



该 MDN 文章中的这些详细信息直接基于 Fetch 规范的以下部分:
https://fetch.spec.whatwg.org/#concept-request-redirect-mode

A request has an associated redirect mode, which is "follow", "error", or "manual".

"manual": Retrieves an opaque-redirect filtered response when a request is met with a redirect so that the redirect can be followed manually.


https://fetch.spec.whatwg.org/#concept-filtered-response-opaque-redirect

opaque-redirect filtered response is a filtered response whose type is "opaqueredirect", status is 0, status message is the empty byte sequence, header list is empty, body is null

an opaque filtered response and an opaque-redirect filtered response are nearly indistinguishable from a network error

关于javascript - 响应 header 不可用于获取 'redirect: manual' 的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52666207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com