简体   繁体   中英

cannot get the json body of the request

Trying to get the body of the body using fetch and with the authentication of adobe. I always get this 200 response (means okay) but I cannot the actual response of body like in postman.

[Symbol(Response internals)]: {
    url: url_of_adobe,
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }

Here's my code

const fetch = require("node-fetch");
const fs = require("fs");

fetch(url, {
    'method': 'GET',
    'Content-Type': 'application/json',
    'headers': {
        'x-gw-ims-org-id': org_id,
        'x-api-key': api_key,
        'Authorization': `Bearer ${accessToken}`, 
    },
    
}).then((response) => console.log(response))
    .catch((error) => console.log(error));

Content-Type should be in the header

'headers': {
        'Content-Type': 'application/json',
        'x-gw-ims-org-id': org_id,
        'x-api-key': api_key,
        'Authorization': `Bearer ${accessToken}`, 
    },

And if you want to read the response in json format you have to use .json() on the response

.then((response) => console.log(response.json()))
    .catch((error) => console.log(error));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM