Azi*_*ima 6 post node.js postman node-fetch
我正在尝试发送带有正文的 POST 请求,form-data因为这似乎是唯一有效的方法。
我也在邮递员中尝试过此操作,但发送body不起作用raw JSON。
所以我尝试做同样的事情,node-fetch但似乎body正在发送,JSON并且我得到了与以前相同的错误(当raw从邮递员使用时)。
try{
const { streamId } = request.body;
const headers = {
"Authorization": INO_AUTHORIZATION_CODE,
// "Content-Type": "multipart/form-data; boundary=<calculated when request is sent>"
"Content-Type": "application/json"
}
const url = `https://www.inoreader.com/reader/api/0/stream/contents/${streamId}`;
const body = {
AppId: INO_APP_ID,
AppKey: INO_APP_KEY
}
const resp = await fetch(url, {
method: 'POST',
body: JSON.stringify(body),
// body: body,
headers: headers
});
const json = await resp.text();
return response.send(json);
} catch(error) {
next(error);
}
Run Code Online (Sandbox Code Playgroud)
仅将 body 设置为form-data有效:
小智 10
您需要使用其文档中提到的表单数据包, 以便您的代码将是
const FormData = require('form-data');
const form = new FormData();
form.append('AppId', INO_APP_ID);
form.append('AppKey', INO_APP_KEY);
const resp = await fetch(url, {
method: 'POST',
body: form
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21686 次 |
| 最近记录: |