智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
LightingSystemApp-serial/.svn/pristine/8e/8e03c3af5ca9afe178ee09e5441...

42 lines
1.1 KiB

let pkg = require('./../../package.json');
let req = require("request");
module.exports = function (request, responseCallBack) {
//自动管理cookie
let config = {jar: true, proxy: request.proxy}
let rq = req.defaults(config)
let headers = request.headers;
if (!headers['User-Agent'] && !headers['user-agent']) {
headers['User-Agent'] = 'fly/' + pkg.version;
}
//支持gzip
request.gzip = true;
if (request.hasOwnProperty("timeout") && request.timeout < 1) {
//use request lib default timeout
delete request.timeout;
}
let ret = {
statusCode: 0
}
if (request.responseType === "stream") {
delete request.responseType;
request.encoding=null;
}
rq(request, function (error, response, body) {
if (error) {
ret.statusMessage = error.message
} else {
ret.statusCode = response.statusCode
ret.responseText = body;
ret.headers = response.headers;
ret.statusMessage = response.statusMessage;
ret.response = response;
}
responseCallBack(ret)
})
}