check if body is an object

This commit is contained in:
Flummi 2020-02-13 14:53:01 +01:00
parent 203422b272
commit e9e6f47d98

View File

@ -17,7 +17,7 @@ const readdata = (res, mode, data = "") => new Promise((resolve, reject) => res
export default (a, options = {}, link = url.parse(a), body = "") => new Promise((resolve, reject) => { export default (a, options = {}, link = url.parse(a), body = "") => new Promise((resolve, reject) => {
options = {...{ hostname: link.hostname, path: link.path, method: "GET" }, ...options}; options = {...{ hostname: link.hostname, path: link.path, method: "GET" }, ...options};
if(options.method === "POST") { if(options.method === "POST") {
body = querystring.stringify(options.body); body = typeof options.body === "object" ? querystring.stringify(options.body) : options.body;
delete options.body; delete options.body;
options.headers = {...options.headers, ...{ options.headers = {...options.headers, ...{
"Content-Type": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded",