URL 定义 Response 对象时为空
URL is empty when defining a Response object
我正在尝试创建这样的响应请求:
Response { type: "basic", url: "https://mywebsite.com/download?lang=en", status: 200, ok: true, statusText: "SuperSmashingGreat!"}
我阅读了 here 如何设置新的 Response
对象,并且尝试了:
var myBlob = new Blob();
var init = {
"status": 200,
"statusText": "SuperSmashingGreat!",
"url": "https://mywebsite.com/download?lang=en",
"ok": "true"
};
var myResponse = new Response(myBlob, init);
console.log(myResponse)
在我 运行 它之后,我收到了这个没有 url 的 Response
对象(它是空的 url: ""
):
{
type: "default",
url: "",
redirected: false,
status: 200,
ok: true,
statusText: "SuperSmashingGreat!",
headers: Headers,
body: ReadableStream,
bodyUsed: false
}
为什么没有设置?
感谢@Blair Nangle 的评论,基于 。
我用过:
Object.defineProperty(resp, "url", { value: "foobar" });
完整的工作代码:
var myBlob = new Blob();
var init = {
"status": 200,
"statusText": "SuperSmashingGreat!",
"url": "https://mywebsite.com/download?lang=en",
"ok": "true"
};
var resp = new Response(myBlob, init);
Object.defineProperty(resp, "resp", { value: "https://mywebsite.com/download?lang=en" });
console.log(myResponse)
我正在尝试创建这样的响应请求:
Response { type: "basic", url: "https://mywebsite.com/download?lang=en", status: 200, ok: true, statusText: "SuperSmashingGreat!"}
我阅读了 here 如何设置新的 Response
对象,并且尝试了:
var myBlob = new Blob();
var init = {
"status": 200,
"statusText": "SuperSmashingGreat!",
"url": "https://mywebsite.com/download?lang=en",
"ok": "true"
};
var myResponse = new Response(myBlob, init);
console.log(myResponse)
在我 运行 它之后,我收到了这个没有 url 的 Response
对象(它是空的 url: ""
):
{
type: "default",
url: "",
redirected: false,
status: 200,
ok: true,
statusText: "SuperSmashingGreat!",
headers: Headers,
body: ReadableStream,
bodyUsed: false
}
为什么没有设置?
感谢@Blair Nangle 的评论,基于
我用过:
Object.defineProperty(resp, "url", { value: "foobar" });
完整的工作代码:
var myBlob = new Blob();
var init = {
"status": 200,
"statusText": "SuperSmashingGreat!",
"url": "https://mywebsite.com/download?lang=en",
"ok": "true"
};
var resp = new Response(myBlob, init);
Object.defineProperty(resp, "resp", { value: "https://mywebsite.com/download?lang=en" });
console.log(myResponse)