"use strict"; cc._RF.push(module, 'a2af0lfNIRPj6O7NvL1gMR1', 'Http'); // Script/Http.ts "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Global_1 = require("./Global"); var URL = "https://www.19960909.com"; // 39.98.43.215:9000; // let URL = "http://192.168.3.137:9001" var Http = /** @class */ (function () { function Http() { } Http.sendRequest = function (path, data, handler, extraUrl) { return; var xhr = new XMLHttpRequest(); xhr.timeout = 5000; var str = "?msg=" + JSON.stringify(data); // for(var k in data){ // if(str != "?"){ // str += "&"; // } // str += k + "=" + data[k]; // } if (extraUrl == null) { extraUrl = Http.url; } var requestURL = extraUrl + path + encodeURI(str); console.log("RequestURL:" + requestURL); xhr.open("GET", requestURL, true); if (cc.sys.isNative) { xhr.setRequestHeader("Accept-Encoding", "gzip,deflate"); xhr.setRequestHeader("contentType", "text/html;charset=UTF-8"); } xhr.onreadystatechange = function () { if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) { Global_1.default.instance.NetStatus = true; //console.log("http res("+ xhr.responseText.length + "):" + xhr.responseText); try { console.log("------------------1"); var ret = JSON.parse(xhr.responseText); if (handler !== null) { handler(ret); } /* code */ } catch (e) { console.log("err:" + e); //handler(null); } finally { // if(cc.vv && cc.vv.wc){ // // cc.vv.wc.hide(); // } } } else { //Global.instance.NetStatus = false; } }; // if(cc.vv && cc.vv.wc){ // //cc.vv.wc.show(); // } try { xhr.send(); } catch (error) { Global_1.default.instance.NetStatus = false; //console.log(" Global.instance.NetStatus "+Global.instance.NetStatus); console.log("HTTP " + error); } return xhr; }; ; Http.sendPost = function (path, data, handler, extraUrl) { return; var xhr = new XMLHttpRequest(); xhr.timeout = 5000; xhr.open("POST", Http.url + path, true); // xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");//缺少这句,后台无法获取参数 xhr.setRequestHeader("Content-type", "application/json"); xhr.onreadystatechange = function () { //console.info(xhr.getResponseHeader('content-type')==='application/json'); if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) { Global_1.default.instance.NetStatus = true; //console.log("http res("+ xhr.responseText.length + "):" + xhr.responseText); try { console.log("------------------2"); var ret = JSON.parse(xhr.responseText); if (handler !== null) { handler(ret); } /* code */ } catch (e) { console.log("err:" + e); //handler(null); } finally { // if(cc.vv && cc.vv.wc){ // // cc.vv.wc.hide(); // } } } else { } }; //console.info(JSON.stringify(data)); try { xhr.send("a=1&a=2"); } catch (error) { Global_1.default.instance.NetStatus = false; } return xhr; }; ; // let origin:number = 0; // static sessionId:number; // static userId:number; // static master_url:number; Http.url = URL; return Http; }()); exports.default = Http; cc._RF.pop();