获取获取响应数据

getting Fetch response data

我正在使用 chrome devTools 来镜像 webRequest。查看网络请求,响应中有一些 JSON 数据我想访问

右击 --> 复制为提取 -->

fetch(
    "https://www.url.com/service.svc?action=FindConversation&ID=-40&AC=1",
    {
        "credentials":"include",
        "headers":{
            "accept":"*/*",
            "accept-language":"en-US,en;q=0.9",
            "action":"FindConversation",
            "content-type":"application/json; charset=UTF-8",
            "actionid":"-40",
            "unique_identifier":"062lCufCY0i5mI9NMTRUsF87XDq9ttYIonzZQjBcCOPvzoIJFOTSI6ZVNK9lMwy_iPFY2tuZzPY."
            "x-requested-with":"XMLHttpRequest"
        },
        "referrer":"https://ballard.amazon.com/OWA/",
        "referrerPolicy":"no-referrer-when-downgrade",
        "body":"contains some body data I want to manipulate",
        "method":"POST",
        "mode":"cors"
    }
).then(res => {console.log(res)})

这会打印出如下内容:

Response {type: "basic", url: "https://url/service.svc?action=FindConversation&ID=-40&AC=1", redirected: false, status: 200, ok: true, …}
body: ReadableStream
locked: false
__proto__: ReadableStream
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "basic"
url: "https://url/OWA/service.svc?action=FindConversation&ID=-40&AC=1"
__proto__: Response

当我检查我刚刚发出的网络请求时,它似乎没有 returning 任何 JSON 数据,而是用 200 代码响应。那是正常的吗?

我要么期望它是 return JSON 数据,要么失败。

此外,JSON 响应数据在 res 中的什么位置?

这是正常现象。 fetch() returns 一个 stream object 而不仅仅是 body.

使用res.json()提取JSON内容。 对于非 JSON 响应,使用 res.text()