a2af095f-3484-4f8f-a3bb-36f2f580c475.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. "use strict";
  2. cc._RF.push(module, 'a2af0lfNIRPj6O7NvL1gMR1', 'Http');
  3. // Script/Http.ts
  4. "use strict";
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var Global_1 = require("./Global");
  7. var URL = "https://www.19960909.com";
  8. // 39.98.43.215:9000;
  9. // let URL = "http://192.168.3.137:9001"
  10. var Http = /** @class */ (function () {
  11. function Http() {
  12. }
  13. Http.sendRequest = function (path, data, handler, extraUrl) {
  14. return;
  15. var xhr = new XMLHttpRequest();
  16. xhr.timeout = 5000;
  17. var str = "?msg=" + JSON.stringify(data);
  18. // for(var k in data){
  19. // if(str != "?"){
  20. // str += "&";
  21. // }
  22. // str += k + "=" + data[k];
  23. // }
  24. if (extraUrl == null) {
  25. extraUrl = Http.url;
  26. }
  27. var requestURL = extraUrl + path + encodeURI(str);
  28. console.log("RequestURL:" + requestURL);
  29. xhr.open("GET", requestURL, true);
  30. if (cc.sys.isNative) {
  31. xhr.setRequestHeader("Accept-Encoding", "gzip,deflate");
  32. xhr.setRequestHeader("contentType", "text/html;charset=UTF-8");
  33. }
  34. xhr.onreadystatechange = function () {
  35. if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {
  36. Global_1.default.instance.NetStatus = true;
  37. //console.log("http res("+ xhr.responseText.length + "):" + xhr.responseText);
  38. try {
  39. console.log("------------------1");
  40. var ret = JSON.parse(xhr.responseText);
  41. if (handler !== null) {
  42. handler(ret);
  43. } /* code */
  44. }
  45. catch (e) {
  46. console.log("err:" + e);
  47. //handler(null);
  48. }
  49. finally {
  50. // if(cc.vv && cc.vv.wc){
  51. // // cc.vv.wc.hide();
  52. // }
  53. }
  54. }
  55. else {
  56. //Global.instance.NetStatus = false;
  57. }
  58. };
  59. // if(cc.vv && cc.vv.wc){
  60. // //cc.vv.wc.show();
  61. // }
  62. try {
  63. xhr.send();
  64. }
  65. catch (error) {
  66. Global_1.default.instance.NetStatus = false;
  67. //console.log(" Global.instance.NetStatus "+Global.instance.NetStatus);
  68. console.log("HTTP " + error);
  69. }
  70. return xhr;
  71. };
  72. ;
  73. Http.sendPost = function (path, data, handler, extraUrl) {
  74. return;
  75. var xhr = new XMLHttpRequest();
  76. xhr.timeout = 5000;
  77. xhr.open("POST", Http.url + path, true);
  78. // xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");//缺少这句,后台无法获取参数
  79. xhr.setRequestHeader("Content-type", "application/json");
  80. xhr.onreadystatechange = function () {
  81. //console.info(xhr.getResponseHeader('content-type')==='application/json');
  82. if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {
  83. Global_1.default.instance.NetStatus = true;
  84. //console.log("http res("+ xhr.responseText.length + "):" + xhr.responseText);
  85. try {
  86. console.log("------------------2");
  87. var ret = JSON.parse(xhr.responseText);
  88. if (handler !== null) {
  89. handler(ret);
  90. } /* code */
  91. }
  92. catch (e) {
  93. console.log("err:" + e);
  94. //handler(null);
  95. }
  96. finally {
  97. // if(cc.vv && cc.vv.wc){
  98. // // cc.vv.wc.hide();
  99. // }
  100. }
  101. }
  102. else {
  103. }
  104. };
  105. //console.info(JSON.stringify(data));
  106. try {
  107. xhr.send("a=1&a=2");
  108. }
  109. catch (error) {
  110. Global_1.default.instance.NetStatus = false;
  111. }
  112. return xhr;
  113. };
  114. ;
  115. // let origin:number = 0;
  116. // static sessionId:number;
  117. // static userId:number;
  118. // static master_url:number;
  119. Http.url = URL;
  120. return Http;
  121. }());
  122. exports.default = Http;
  123. cc._RF.pop();