mm_https 1.5.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/index.js +14 -16
  2. package/nodemon.json +19 -0
  3. package/package.json +1 -1
  4. package/test.js +27 -11
package/index.js CHANGED
@@ -38,8 +38,8 @@ class Http {
38
38
  // 'sec-fetch-mode': 'navigate',
39
39
  // 'sec-fetch-site': 'none',
40
40
  // 'sec-fetch-user': '?1',
41
- 'Upgrade-Insecure-Requests': '1',
42
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'
41
+ // 'Upgrade-Insecure-Requests': '1',
42
+ // 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'
43
43
  },
44
44
  rejectUnauthorized: false,
45
45
  cookie: "",
@@ -207,13 +207,14 @@ Http.prototype.req = async function(options) {
207
207
  this.post_option(op);
208
208
  }
209
209
  var res = await this.request(op);
210
- if (res.statusCode == 302) {
211
- var url = headers.location;
212
- var lt = headers['set-cookie'];
210
+ console.log(op);
211
+ if (res.status.code == 302) {
212
+ var url = res.headers.location;
213
+ var lt = res.headers['set-cookie'];
213
214
  if (lt) {
214
215
  var len = lt.length;
215
216
  for (var i = 0; i < len; i++) {
216
- _this.set_cookie(lt[i]);
217
+ this.set_cookie(lt[i]);
217
218
  }
218
219
  options.href = url;
219
220
  op = this.http_options(options);
@@ -268,17 +269,12 @@ Http.prototype.request = function(options) {
268
269
  return new Promise(function(resolve, reject) {
269
270
  var body = '';
270
271
  var req = hp.request(options, (res) => {
272
+ var {
273
+ headers
274
+ } = res;
271
275
  if (res.statusCode == 200) {
272
- var {
273
- headers
274
- } = res;
275
276
  var chunks = [];
276
277
  var encoding = headers['content-encoding'];
277
- if (encoding) {
278
- // res.setEncoding('utf-8');
279
- } else {
280
- res.setEncoding("binary");
281
- }
282
278
  res.on('data', function(d) {
283
279
  chunks.push(d);
284
280
  }).on('end', function(d) {
@@ -307,11 +303,13 @@ Http.prototype.request = function(options) {
307
303
  resolve({
308
304
  status: 200,
309
305
  headers,
310
- body: body
306
+ buffer,
307
+ body
311
308
  });
312
309
  });
313
310
  } else {
314
311
  resolve({
312
+ headers,
315
313
  status: {
316
314
  code: res.statusCode,
317
315
  message: res.statusMessage
@@ -404,7 +402,7 @@ Http.prototype.download = async function(url, filename, auto, headers, cookie) {
404
402
  file = filename;
405
403
  }
406
404
  if (file) {
407
- var length = await fs.writeFileSync(file, res.body, "binary");
405
+ var length = await fs.writeFileSync(file, res.buffer, "binary");
408
406
  if (length == 0) {
409
407
  file = null;
410
408
  }
package/nodemon.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "restartable": "rs",
3
+ "ignore": [
4
+ ".git",
5
+ ".svn",
6
+ "node_modules/**/node_modules",
7
+ "static"
8
+ ],
9
+ "verbose": true,
10
+ "execMap": {
11
+ "": "node",
12
+ "js": "node --harmony"
13
+ },
14
+ "env": {
15
+ "NODE_ENV": "development"
16
+ },
17
+ "ext": "js ts json",
18
+ "legacy-watch": false
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_https",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "这是超级美眉http请求帮助类模块,可自动补充cookie,实现模拟登录,通讯",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js CHANGED
@@ -1,8 +1,14 @@
1
1
  // const nJwt = require('njwt');
2
- var http = require('http');
3
2
  var Http = require('./index.js');
4
3
  var fs = require("fs");
5
4
 
5
+ async function test(){
6
+ var http = new Http();
7
+ // var res = await http.get("https://www.baidu.com/");
8
+ var res = await http.get("https://www.hao123.com/");
9
+ console.log("html", res);
10
+ }
11
+
6
12
  // async function test3() {
7
13
  // // 将「微信对话开放平台」得到的信息填入
8
14
  // var APPID = "xxx";
@@ -25,7 +31,6 @@ var fs = require("fs");
25
31
  // }
26
32
  // test3();
27
33
 
28
-
29
34
  // async function test2(content, from_user) {.
30
35
  // 图灵机器人
31
36
  // const apikey = "xxx";
@@ -94,19 +99,30 @@ var fs = require("fs");
94
99
  // // console.log('结果:', hp.cookies);
95
100
  // }
96
101
 
97
- async function test() {
98
- var hp = new Http();
99
- hp.config.headers.Accept = "application/javascript; charset=UTF-8";
100
- var url =
101
- "http://69.push2.eastmoney.com/api/qt/clist/get?cb=jQuery1124007023275733383882_1586573202818&pn=1&pz=100000&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&fid=f3&fs=m:0+t:6,m:0+t:13,m:0+t:80,m:1+t:2,m:1+t:23&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152";
102
- var res = await hp.get(url);
103
- }
102
+ // async function test() {
103
+ // var hp = new Http();
104
+ // hp.config.headers.Accept = "application/javascript; charset=UTF-8";
105
+ // var url =
106
+ // "http://69.push2.eastmoney.com/api/qt/clist/get?cb=jQuery1124007023275733383882_1586573202818&pn=1&pz=100000&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&fid=f3&fs=m:0+t:6,m:0+t:13,m:0+t:80,m:1+t:2,m:1+t:23&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152";
107
+ // var res = await hp.get(url);
108
+ // console.log(res);
109
+ // }
110
+
111
+
112
+ // async function test() {
113
+ // var hp = new Http();
114
+ // hp.config.headers.Accept = "application/javascript; charset=UTF-8";
115
+ // var url ="http://localhost:8001/api/wallet/count";
116
+ // var res = await hp.get(url);
117
+ // console.log(res);
118
+ // }
104
119
 
105
120
  // async function test() {
121
+ // console.log("测试")
106
122
  // var hp = new Http();
107
- // var res = await hp.get('http://localhost:8080/dev/img/logo_gray.png');
123
+ // var res = await hp.get('https://www.baidu.com/img/flexible/logo/pc/result.png');
108
124
  // console.log(res);
109
- // fs.writeFile("./logonew.png", res.body, "binary", function(err) {
125
+ // fs.writeFile("./logonew.png", res.buffer, "binary", function(err) {
110
126
  // if (err) {
111
127
  // console.log("下载失败");
112
128
  // }