emulator/jcfw/logger/httpclient.js
2019-06-11 20:01:47 +08:00

51 lines
1.1 KiB
JavaScript

var httpcli = require('./httpcli');
module.exports = {
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
// start () {},
// update (dt) {},
getInstance() {
if (!this._instance) {
this._instance = new httpcli();
this._instance.init();
this._instance.setRetryInterval(3000);
this._instance.setNeedRetry(true);
}
return this._instance;
},
httpGet(url, cbRes, cbErr) {
// var realurl = url;
// if(urldata){
// if(realurl.indexOf("?") == -1){
// realurl += "?";
// }else{
// realurl += "&";
// }
// realurl += encodeURIComponent(urldata);
// }
return this.httpsend(url, null, cbRes, cbErr, 'GET');
},
httpPost(url, postdata, cbRes, cbErr) {
return this.httpsend(url, postdata, cbRes, cbErr, 'POST');
},
httpsend(url, urldata, cbRes, cbErr, smethod) {
return this.getInstance().httpsend(url, urldata, cbRes, cbErr, smethod);
},
JSON_parse(text) {
try {
return JSON.parse(text);
} catch (err) {
console.log(err);
return null;
}
}
};