小编Jul*_*kin的帖子

获取请求返回状态 cors 和可读流

我正在对我的后端进行提取调用,这是调用。

\n\n

\r\n
\r\n
    const response = await fetch(apiUrl + \'/recipes\', {\r\n      method: \'POST\',\r\n      headers: {\r\n        \'Content-Type\': \'application/json\',\r\n        \'Authorization\': `Token token=${user.token}`\r\n      },\r\n      body: JSON.stringify({\r\n        recipe: {\r\n          recipeId: uri\r\n        }\r\n      })\r\n    })
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n\n

然后这是我在后端发送呼叫的路线

\n\n

\r\n
\r\n
router.post(\'/recipes\', requireToken, (req, res) => {\r\n  req.body.recipe.owner = req.user.id\r\n  Recipe.create(req.body.recipe)\r\n    .then(recipe => {\r\n      console.log(\'Recipe object saved is\', recipe)\r\n      res.status(201).json({ recipe: recipe.toObject() })\r\n    })\r\n    .catch(err => handle(err, res))\r\n})
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n\n

当我这样做时,正确的对象会在发回之前记录。这是记录内容的示例

\n\n

\r\n
\r\n
{ __v: 0,\r\n  updatedAt: 2018-10-19T15:47:16.809Z,\r\n  createdAt: …
Run Code Online (Sandbox Code Playgroud)

javascript http fetch

2
推荐指数
1
解决办法
4024
查看次数

标签 统计

fetch ×1

http ×1

javascript ×1