我正在使用 Node.js 请求模块向 Node.js 请求休息服务器。如果传入数据大小超出允许的限制,我想取消流。这样做的目的是确保我的网络没有被锁定。
我的代码示例如下;
var http = require("http");
async function httpRequest({
host,
method,
port,
path
} = params, data) {
if (method.toUpperCase() === "GET") {
let query = "";
data = JSON.parse(data);
for (var key in data) {
if (data.hasOwnProperty(key)) {
let value = data[key];
console.log(key + " -> " + value);
query = query
.concat("&")
.concat(key)
.concat("=")
.concat(value);
}
}
if (query) {
query = "?".concat(query.substring(1));
}
path = encodeURI(path.concat(query));
console.log("path : " + path);
}
var …Run Code Online (Sandbox Code Playgroud)