问题描述
我正在尝试从已弃用的 request
包(我在其上使用 request-promise-native
)切换到 node-fetch
。但这两个请求似乎并不相同:
// node-fetch :
const result = await fetch(
`${process.env.PATEXTRACTOR_URL}/api/v2/graph`,{
method: "post",body: JSON.stringify(buildPatentExtractBody(selection)),agent: new Agent({ keepAlive: true })
}
).then(result => result.json());
// request-promise-native :
const { data } = await request.post({
url: `${process.env.PATEXTRACTOR_URL}/api/v2/graph`,json: true,body: buildPatentExtractBody(selection),agentOptions: {
keepAlive: true
}
});
node-fetch
失败并显示错误 400(来自目标 API),其中显示“缺少参数或请求类型无法识别”),其中 request-promise-native
成功并返回一个不错的 json 结果。
我看不出这两个请求之间的区别。有什么帮助吗?谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)