38 lines
963 B
JavaScript
38 lines
963 B
JavaScript
var httpcli = require('./httpcli');
|
|
|
|
module.exports = {
|
|
getInstance() {
|
|
if (!this._instance) {
|
|
this._instance = new httpcli();
|
|
this._instance.setRetryInterval(3000);
|
|
this._instance.setNeedRetry(true);
|
|
this._instance.useWeb = false;
|
|
}
|
|
return this._instance;
|
|
},
|
|
setUseWeb(useWeb) {
|
|
this.useWeb = useWeb;
|
|
},
|
|
httpGet(url, cbRes, cbErr) {
|
|
return this.httpsend(url, null, cbRes, cbErr, 'GET');
|
|
},
|
|
|
|
httpPost(url, postdata, cbRes, cbErr, contentType) {
|
|
contentType = contentType || 'text/plain;charset=UTF-8';
|
|
return this.httpsend(url, postdata, cbRes, cbErr, 'POST', contentType);
|
|
},
|
|
|
|
httpsend(url, urldata, cbRes, cbErr, smethod, contentType) {
|
|
return this.getInstance().httpsend(url, urldata, cbRes, cbErr, smethod, false, contentType, this.useWeb);
|
|
},
|
|
|
|
JSON_parse(text) {
|
|
try {
|
|
return JSON.parse(text);
|
|
} catch (err) {
|
|
console.log(err);
|
|
return null;
|
|
}
|
|
}
|
|
};
|