【发布时间】:2020-03-06 07:11:55
【问题描述】:
我得到错误:
UnhandledPromiseRejectionWarning: FetchError: invalid json response body at {url}
reason: Unexpected token < in JSON at position 0
我的代码:
const fetch = require('node-fetch');
const url = 'Reeeealy long url here';
fetch(url)
.then(res => res.json())
.then(console.log);
如果 url 长于 ~8k+ 个字符 api 返回
400 Bad Request
Request Header Or Cookie Too Large
nginx
显然我不控制那个 api。
我能做些什么来防止这种情况发生?
网址结构:
1) 域
2) api版本
3) 端点
4) 请求资料(最长的部分)
5) id 结尾
看起来像这样:https://example.com/v1/endpoint/query?query=long_part_here&ids=2145132,532532,535
【问题讨论】:
标签: javascript node.js fetch node-fetch