mm_https 1.4.6 → 1.4.7

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 (3) hide show
  1. package/index.js +234 -316
  2. package/package.json +6 -5
  3. package/test.js +98 -30
package/index.js CHANGED
@@ -3,75 +3,36 @@
3
3
  * @author <a href="http://qww.elins.cn">邱文武</a>
4
4
  * @version 1.2
5
5
  */
6
+ const http = require('http');
7
+ const https = require('https');
8
+ const HttpProxyAgent = require('https-proxy-agent');
6
9
  const fs = require("fs");
7
10
  const Cookie = require('./cookie');
8
11
  const {
9
- gunzip,
10
- inflate
12
+ unzipSync
11
13
  } = require('zlib');
12
- const http = require('http');
13
- const https = require('https');
14
14
  const iconv = require('iconv-lite');
15
+ const {
16
+ hostname
17
+ } = require('os');
18
+ const {
19
+ header
20
+ } = require('request/lib/hawk');
21
+ const {
22
+ HttpsProxyAgent
23
+ } = require('https-proxy-agent');
15
24
 
16
- /**
17
- * @description 获取参数项
18
- * @param {String} url 网址
19
- * @return {Object} http参数对象
20
- */
21
- function getInfo(url) {
22
- var host = url.between("//", "/", true);
23
- var path = "/" + url.replace("//").right("/");
24
- var index = host.indexOf(':');
25
- var port;
26
-
27
- if (index !== -1) {
28
- port = host.substr(index + 1);
29
- host = host.substr(0, index);
30
- } else {
31
- if (url.indexOf('https') !== -1) {
32
- port = 443;
33
- } else {
34
- port = 80;
35
- }
36
- }
37
- return {
38
- host: host,
39
- port: port,
40
- path: path
41
- }
42
- }
43
-
44
- /**
45
- * http类函数
46
- */
47
25
  class Http {
48
- /**
49
- * 构造函数
50
- * @constructor
51
- * @param {Object} config 配置参数
52
- */
53
26
  constructor(config) {
54
- /**
55
- * 存储上次请求
56
- */
57
- this.referer = "";
58
- /**
59
- * 设置cookie存储
60
- */
61
- this.cookie = new Cookie();
62
-
63
- /**
64
- * 获取的编码方式
65
- */
66
- this.encoding = 'utf-8';
67
-
68
27
  this.config = Object.assign({
69
28
  headers: {
70
- 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
71
- 'accept-encoding': 'gzip, deflate',
29
+ 'accept': 'text/html,application/json,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
30
+ // 'accept-encoding': 'gzip, deflate, br',
31
+ 'accept-encoding': 'deflate',
72
32
  'accept-language': 'zh-CN,zh;q=0.9',
73
- 'cache-control': 'max-age=0',
74
- 'sec-ch-ua': '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
33
+ 'cache-control': 'no-cache',
34
+ 'pragma': 'no-cache',
35
+ 'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="98", "Google Chrome";v="98"',
75
36
  'sec-ch-ua-mobile': '?0',
76
37
  'sec-ch-ua-platform': '"Windows"',
77
38
  'sec-fetch-dest': 'document',
@@ -79,258 +40,95 @@ class Http {
79
40
  'sec-fetch-site': 'none',
80
41
  'sec-fetch-user': '?1',
81
42
  'upgrade-insecure-requests': '1',
82
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36'
43
+ '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'
83
44
  },
84
- rejectUnauthorized: false
85
- }, config)
45
+ rejectUnauthorized: false,
46
+ cookie: "",
47
+ proxy: null
48
+ // proxy: "http://127.0.0.1:10809"
49
+ }, config);
50
+
51
+ /**
52
+ * cookie缓存
53
+ */
54
+ this.cookies = {
55
+
56
+ }
86
57
  }
87
58
  }
88
59
 
89
- /**
90
- * @description 删除cookie
91
- * @param {String} name 名称
92
- * @param {String} path 路径
93
- * @param {String} domain 域名
94
- */
95
- Http.prototype.delCookie = function(name, path, domain) {
96
- if (domain) {
97
- this.list.del({
98
- name: name,
99
- path: path,
100
- domain: domain
101
- });
102
- } else if (path) {
103
- this.list.del({
104
- name: name,
105
- path: path
106
- });
107
- } else {
108
- this.list.del({
109
- name: name
110
- });
60
+ Http.prototype.set_cookie = function(cookieStr) {
61
+ var arr = cookieStr.split('; ');
62
+ var name;
63
+ if (arr.length > 1) {
64
+ var kv = arr[0];
65
+ var arr_kv = kv.split("=");
66
+ name = arr_kv[0];
67
+ this.cookies[name] = encodeURIComponent(arr_kv[1]);
111
68
  }
112
- };
69
+ }
113
70
 
114
- /**
115
- * @description 初始化选项
116
- * @param {String} method 请求方式
117
- * @param {String} url 请求地址
118
- * @param {Object} cookie 缓存
119
- * @return {Object} 配置参数
120
- */
121
- Http.prototype.option = function(method, url, cookie) {
122
- var {
123
- host,
124
- port,
125
- path
126
- } = getInfo(url);
127
- var op = Object.assign({}, this.config, {
128
- url: url,
129
- hostname: host,
130
- path: path,
131
- port: port,
132
- method: method
133
- });
134
- if (cookie) {
135
- op.cookie = cookie;
136
- } else if (this.cookie) {
137
- op.cookie = this.cookie.str();
138
- }
139
- if (this.referer) {
140
- op.Referer = this.referer;
71
+ Http.prototype.get_cookie = function() {
72
+ var dist = this.cookies;
73
+ var str = "";
74
+ for(var k in dist)
75
+ {
76
+ str += "; " + k + "=" + dist[k];
141
77
  }
142
- return op;
143
- };
144
-
145
- /**
146
- * http请求
147
- * @param {Object} options 请求配置
148
- * @param {Object} param 请求参数
149
- * @return {Promise|Object} 请求的结果
150
- */
151
- Http.prototype.req = function(options, param) {
152
- return new Promise((resolve, reject) => {
153
- var hp;
154
- var url = options.url;
155
- if (url && url.indexOf('https') !== -1) {
156
- hp = https;
157
- } else {
158
- hp = http;
159
- }
160
- var req = hp.request(options, function(res) {
161
- var code = res.statusCode;
162
- if (code === 200) {
163
- var chunks = [];
164
- var encoding = res.headers['content-encoding'];
165
- // 非gzip/deflate要转成utf-8格式
166
- if (encoding === 'undefined') {
167
- res.setEncoding(this.encoding);
168
- }
169
- res.on('data', function(chunk) {
170
- chunks.push(chunk);
171
- });
172
- res.on('end', function() {
173
- var buffer = Buffer.concat(chunks);
174
- if (encoding === 'gzip') {
175
- gunzip(buffer, function(err, decoded) {
176
- if (err) {
177
- reject(err);
178
- } else {
179
- var body = decoded.toString();
180
- var mh = body.match(/charset=(gb2312|GBK)"/i);
181
- if (mh) {
182
- body = iconv.decode(decoded, 'GBK');
183
- }
184
- resolve({
185
- headers: res.headers,
186
- binary: decoded,
187
- body: body
188
- });
189
- }
190
- });
191
- } else if (encoding === 'deflate') {
192
- inflate(buffer, function(err, decoded) {
193
- if (err) {
194
- reject(err);
195
- } else {
196
- var body = decoded.toString();
197
- var mh = body.match(/charset=(gb2312|GBK)"/i);
198
- if (mh) {
199
- body = iconv.decode(decoded, 'GBK');
200
- }
201
- resolve({
202
- headers: res.headers,
203
- binary: decoded,
204
- body: body
205
- });
206
- }
207
- });
208
- } else {
209
- var body = buffer.toString();
210
- var mh = body.match(/charset=(gb2312|GBK)"/i);
211
- if (mh) {
212
- body = iconv.decode(buffer, 'GBK');
213
- }
214
- resolve({
215
- headers: res.headers,
216
- binary: buffer,
217
- body: body
218
- });
219
- }
220
- });
221
- } else {
222
- resolve({
223
- status: code,
224
- message: res.statusMessage,
225
- headers: res.headers
226
- });
227
- }
228
- });
229
- if (param) {
230
- req.write(param);
231
- }
232
- req.on("error", function(err) {
233
- resolve({
234
- status: 0,
235
- message: err.message
236
- });
237
- });
238
- req.end();
239
- });
240
- };
78
+ return str;
79
+ }
241
80
 
242
- /**
243
- * @description 执行http请求
244
- * @param {Object} options 配置参数
245
- * @param {Object} param 传递参数
246
- * @return {Object} 执行结果
247
- */
248
- Http.prototype.run = async function(options, param) {
249
- var res = await this.req(options, param);
250
- if (res) {
251
- if (res.status === 302) {
252
- var url = res.headers.location;
253
- var op = this.option(options.method, url);
254
- res = await this.req(op, param);
255
- if (res.status === 302) {
256
- var url = res.headers.location;
257
- op = this.option(options.method, url);
258
- res = await this.req(op, param);
259
- }
260
- }
261
- var hd = res.headers;
262
- if (hd) {
263
- var lt = hd['set-cookie'];
264
- if (lt) {
265
- var len = lt.length;
266
- for (var i = 0; i < len; i++) {
267
- this.cookie.str(lt[i]);
268
- }
269
- }
270
- this.referer = options.url;
271
- }
81
+ Http.prototype.options = function(options) {
82
+ return {
83
+ url: "",
84
+ method: "GET",
85
+ body: {},
86
+ proxy: "http://127.0.0.1:10809",
87
+ headers: Object.assign({}, this.config.headers)
272
88
  }
273
- return res;
274
- };
89
+ }
275
90
 
276
- /**
277
- * @description 执行http请求 —— 快速
278
- * @param {Object} options 配置参数
279
- * @param {Object} param 传递参数
280
- * @return {Object} 执行结果
281
- */
282
- Http.prototype.run_fast = async function(options, param) {
283
- var res = await this.req(options, param);
284
- if (res) {
285
- if (res.status === 302) {
286
- var url = res.headers.location;
287
- var op = this.option(options.method, url);
288
- res = await this.req(op, param);
289
- if (res.status === 302) {
290
- var url = res.headers.location;
291
- op = this.option(options.method, url);
292
- res = await this.req(op, param);
293
- }
294
- }
91
+ Http.prototype.http_options = function(options) {
92
+ var cg = this.config;
93
+ var {
94
+ url,
95
+ body,
96
+ headers,
97
+ method,
98
+ cookie
99
+ } = options;
100
+ var protocol = url.left(":/") || 'http';
101
+ // 移除协议头 取端口号
102
+ var u = url.replace(protocol + "://", "");
103
+ var port = u.between(":", "/") || u.right(":") || (protocol === 'http' ? 80 : 443);
104
+ // 移除端口号,取主机地址
105
+ u = u.replace(":" + port, "");
106
+ var hostname = u.left("/", true).left("?", true);
107
+ // 移除主机地址,取路由路径
108
+ u = u.replace(hostname, "");
109
+ var path = u;
110
+ if(cookie){
111
+ this.set_cookie(cookie);
295
112
  }
296
- return res;
297
- };
298
-
299
- /**
300
- * @description GET请求
301
- * @param {String} url 请求地址
302
- * @param {Object} headers 请求头
303
- * @param {Object} cookie 服务缓存
304
- * @return {Object} 请求的结果
305
- */
306
- Http.prototype.get = async function(url, headers, cookie) {
307
- var op = this.option('GET', url, cookie);
308
- $.push(op.headers, headers, true);
309
- return await this.run(op);
310
- };
311
-
312
- /**
313
- * @description GET请求 —— 快速
314
- * @param {String} url 请求地址
315
- * @return {Object} 请求的结果
316
- */
317
- Http.prototype.get_fast = async function(url) {
318
- var op = this.option('GET', url, {});
319
- return await this.run_fast(op);
320
- };
113
+ return {
114
+ url,
115
+ protocol,
116
+ hostname,
117
+ body,
118
+ port: Number(port),
119
+ path: path.indexOf("/") === 0 ? path : "/" + path,
120
+ method: method || "GET",
121
+ headers: headers ? Object.assign({}, cg.headers, headers) : Object.assign({}, cg.headers),
122
+ agent: cg.proxy ? new HttpProxyAgent(cg.proxy) : null,
123
+ cookie: this.get_cookie()
124
+ }
125
+ }
321
126
 
322
- /**
323
- * @description POST请求
324
- * @param {String} url 请求地址
325
- * @param {Object} param 正文参数
326
- * @param {Object} headers 请求头
327
- * @param {String} type 请求类型
328
- * @param {String} cookie Cookie缓存
329
- * @return {Object} 请求的结果
330
- */
331
- Http.prototype.post = async function(url, param, headers, type, cookie) {
127
+ Http.prototype.post_option = function(op) {
128
+ var param = op.body;
332
129
  var body = "";
333
130
  var tp = typeof(param);
131
+ var type = op.type;
334
132
  if (tp === "object") {
335
133
  if (!type) {
336
134
  type = 'application/json; charset=UTF-8';
@@ -364,30 +162,150 @@ Http.prototype.post = async function(url, param, headers, type, cookie) {
364
162
  }
365
163
  }
366
164
  }
367
- var op = this.option('POST', url, cookie);
368
165
  op.body = body;
369
166
  op.headers['Content-Type'] = type;
370
167
  op.headers['Content-Length'] = Buffer.byteLength(body);
371
- $.push(op.headers, headers, true);
372
- return await this.run(op, body);
168
+ }
169
+
170
+ /**
171
+ * http请求
172
+ * @param {Object} options 配置
173
+ * @return {Object} 返回执行结果
174
+ */
175
+ Http.prototype.req = async function(options) {
176
+ var op = this.http_options(options);
177
+ if (op.method.toLocaleUpperCase() === "POST") {
178
+ this.post_option(op);
179
+ }
180
+ var res = await this.request(op);
181
+ if (res.statusCode == 302) {
182
+ var url = headers.location;
183
+ var lt = headers['set-cookie'];
184
+ if (lt) {
185
+ var len = lt.length;
186
+ for (var i = 0; i < len; i++) {
187
+ _this.set_cookie(lt[i]);
188
+ }
189
+ options.url = url;
190
+ op = this.http_options(options);
191
+ op.referer = options.url;
192
+ res = await this.request(op);
193
+ }
194
+ } else {
195
+ return res;
196
+ }
197
+ }
198
+
199
+ /**
200
+ * 请求
201
+ * @param {Object} options 配置
202
+ */
203
+ Http.prototype.request = function(options) {
204
+ var hp = options.protocol === "https" ? https : http;
205
+ delete options.protocol;
206
+ var _this = this;
207
+ return new Promise(function(resolve, reject) {
208
+ var body = '';
209
+ var req = hp.request(options, (res) => {
210
+ if (res.statusCode == 200) {
211
+ var { headers } = res;
212
+ var buffer = '';
213
+ var encoding = headers['content-encoding'];
214
+ if (encoding) {
215
+ res.setEncoding('utf-8');
216
+ } else {
217
+ res.setEncoding("binary");
218
+ }
219
+ res.on('data', function(d) {
220
+ buffer += d;
221
+ }).on('end', function(d) {
222
+ switch (encoding) {
223
+ case 'br':
224
+ case 'gzip':
225
+ case 'deflate':
226
+ body = unzipSync(buffer);
227
+ break;
228
+ default:
229
+ body = buffer;
230
+ break;
231
+ }
232
+ var mh = body.match(/charset=(gb2312|GBK)"/i);
233
+ if (mh) {
234
+ body = iconv.decode(buffer, 'GBK');
235
+ }
236
+ var lt = headers['set-cookie'];
237
+ if (lt) {
238
+ var len = lt.length;
239
+ for (var i = 0; i < len; i++) {
240
+ _this.set_cookie(lt[i]);
241
+ }
242
+ }
243
+ resolve({
244
+ status: 200,
245
+ headers,
246
+ binary: buffer,
247
+ body: body
248
+ });
249
+ });
250
+ } else {
251
+ resolve({
252
+ status: {
253
+ code: res.statusCode,
254
+ message: res.statusMessage
255
+ }
256
+ });
257
+ reject(res);
258
+ }
259
+ });
260
+
261
+ req.on("error", function(err) {
262
+ resolve({
263
+ status: 0,
264
+ message: err.message
265
+ });
266
+ reject(err);
267
+ });
268
+ if (options.method.toLocaleUpperCase() == "POST") {
269
+ req.write(options.body);
270
+ }
271
+ req.end();
272
+ });
273
+ }
274
+
275
+ /**
276
+ * @description GET请求
277
+ * @param {String} url 请求地址
278
+ * @param {Object} headers 请求头
279
+ * @param {Object} cookie 服务缓存
280
+ * @return {Object} 响应的结果
281
+ */
282
+ Http.prototype.get = async function(url, headers, cookie) {
283
+ return await this.req({
284
+ method: "GET",
285
+ url,
286
+ headers,
287
+ cookie
288
+ });
373
289
  };
374
290
 
291
+
375
292
  /**
376
- * @description POST请求 —— 快速
293
+ * @description POST提交
377
294
  * @param {String} url 请求地址
378
- * @param {String} body 正文参数
379
- * @param {String} type 请求类型
380
- * @return {Object} 请求的结果
295
+ * @param {Object} body 提交参
296
+ * @param {Object} headers 请求头
297
+ * @param {Number} type 传参方式 json, form, text
298
+ * @param {Object} cookie 服务缓存
299
+ * @return {Object} 响应的结果
381
300
  */
382
- Http.prototype.post_fast = async function(url, body, type) {
383
- var op = this.option('POST', url, {});
384
- op.body = body;
385
- if (!type) {
386
- type = "application/json; charset=UTF-8";
387
- }
388
- op.headers['Content-Type'] = type;
389
- op.headers['Content-Length'] = Buffer.byteLength(body);
390
- return await this.run_fast(op, body);
301
+ Http.prototype.post = async function(url, body, headers, type, cookie) {
302
+ return await this.req({
303
+ method: "POST",
304
+ url,
305
+ body,
306
+ headers,
307
+ cookie
308
+ });
391
309
  };
392
310
 
393
311
  /**
@@ -414,8 +332,9 @@ Http.prototype.download = async function(url, filename, auto, headers, cookie) {
414
332
  }
415
333
  } else {
416
334
  var content_type = res.headers["content-type"];
417
- var type = content_type.replace("image/", "").replace("application/x-", "").replace("text/", "").replace("audio/",
418
- "").replace("audio/", "").replace("jpeg", "jpg");
335
+ var type = content_type.replace("image/", "").replace("application/x-", "").replace("text/", "")
336
+ .replace("audio/",
337
+ "").replace("audio/", "").replace("jpeg", "jpg");
419
338
  file = filename + "." + type;
420
339
  }
421
340
  } else {
@@ -437,8 +356,7 @@ Http.prototype.download = async function(url, filename, auto, headers, cookie) {
437
356
  * 清除缓存
438
357
  */
439
358
  Http.prototype.clear = function() {
440
- this.cookie.list.clear();
441
- this.headers = [];
359
+ this.cookies = {};
442
360
  };
443
361
 
444
362
  if (global.$) {
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
- {
1
+ {
2
2
  "name": "mm_https",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "这是超级美眉http请求帮助类模块,可自动补充cookie,实现模拟登录,通讯",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "node test.js"
7
+ "test": "node test.js",
8
+ "dev": "nodemon test.js"
8
9
  },
9
10
  "repository": {
10
11
  "type": "git",
@@ -30,8 +31,8 @@
30
31
  },
31
32
  "homepage": "https://github.com/qiuwenwu/mm_https#readme",
32
33
  "dependencies": {
34
+ "https-proxy-agent": "^5.0.1",
33
35
  "iconv-lite": "^0.5.0",
34
36
  "mm_expand": "^1.4.7"
35
- },
36
- "devDependencies": {}
37
+ }
37
38
  }
package/test.js CHANGED
@@ -20,10 +20,11 @@ var fs = require("fs");
20
20
  // query: token
21
21
  // };
22
22
  // var res = await hp.post('https://openai.weixin.qq.com/openapi/message/' + TOKEN, pm);
23
- // console.log(res.body)
23
+ // console.log(res.message, res.body)
24
24
  // }
25
25
  // test3();
26
26
 
27
+
27
28
  // async function test2(content, from_user) {.
28
29
  // 图灵机器人
29
30
  // const apikey = "xxx";
@@ -53,25 +54,45 @@ var fs = require("fs");
53
54
  // }
54
55
  // test2("真的", "we21lkjq3l");
55
56
 
56
- // 测试
57
+
58
+ // // 测试
57
59
  // async function test() {
58
- // var hp = new Http();
59
- // // var res = await hp.get("http://www.baidu.com");
60
- // // console.log('百度:' + JSON.stringify(res));
61
- // res = await hp.post("http://api.bitcentre.com.cn/login", {
60
+ // var hp = new Http({
61
+ // proxy: "http://127.0.0.1:10809"
62
+ // });
63
+ // res = await hp.post("https://accounts.binance.com/bapi/accounts/v2/public/authcenter/login", {
62
64
  // 'phone': "15817188815",
63
65
  // 'password': "asd123"
64
66
  // }, null, 'form');
65
- // console.log('登录:' + JSON.stringify(res));
66
- // console.log('cookie:', hp.cookie);
67
- // var token = hp.cookie.get('x-auth-token').value;
68
- // console.log('访问牌:' + token);
69
- // res = await hp.get("http://api.bitcentre.com.cn/paper/id?id=1", {
70
- // "x-auth-token": token
71
- // });
72
- // console.log('结果:' + JSON.stringify(res));
67
+ // var token = hp.cookies['x-auth-token'];
68
+ // // res = await hp.get("http://api.bitcentre.com.cn/paper/id?id=1", {
69
+ // // "x-auth-token": token
70
+ // // });
71
+
72
+ // // res = await hp.get("https://www.google.com");
73
+ // console.log('结果:', res);
74
+ // console.log('结果:', hp.cookies);
73
75
  // }
74
76
 
77
+ // 测试
78
+ async function test() {
79
+ var hp = new Http();
80
+ // var res = await hp.get("http://www.baidu.com");
81
+ // console.log('百度:' + JSON.stringify(res));
82
+ res = await hp.post("http://127.0.0.1:8000/login", {
83
+ 'phone': "15817188815",
84
+ 'password': "asd123"
85
+ }, null, 'text');
86
+ console.log('登录:' + JSON.stringify(res));
87
+ var token = hp.cookies['x-auth-token'];
88
+ console.log('访问牌:' + token);
89
+ res = await hp.get("http://127.0.0.1:8000/paper/id?id=1", {
90
+ "x-auth-token": token || ""
91
+ });
92
+ console.log('结果:' + JSON.stringify(res));
93
+ console.log('结果:', hp.cookies);
94
+ }
95
+
75
96
  // async function test () {
76
97
  // var hp = new Http();
77
98
  // var res = await hp.get_fast('http://www.hao123.com');
@@ -101,22 +122,69 @@ var fs = require("fs");
101
122
  // test();
102
123
 
103
124
 
104
- async function download(){
105
- var hp = new Http();
106
- // var url = "http://www.haoduoma.com/d/file/p/2021-06-18/76df67e451ca9dec9991588ad7fda6e6.jpg";
107
- var url = "https://www.copipi.com/p/224/224/becce1fc21d723614b598f5377d5d676.jpg";
108
- "./二维码/中文".addDir();
109
- var filename = "./二维码/你好.jpg".fullname();
110
- var file = await hp.download(url, filename);
111
- console.log(file);
112
- }
113
- download();
114
-
115
- // async function test(){
125
+ // async function download(){
116
126
  // var hp = new Http();
117
- // var url = "https://weibo.com/p/1003061669879400";
118
- // var res = await hp.get(url);
119
- // console.log(res);
127
+ // // var url = "http://www.haoduoma.com/d/file/p/2021-06-18/76df67e451ca9dec9991588ad7fda6e6.jpg";
128
+ // var url = "https://www.copipi.com/p/224/224/becce1fc21d723614b598f5377d5d676.jpg";
129
+ // "./二维码/中文".addDir();
130
+ // var filename = "./二维码/你好.jpg".fullname();
131
+ // var file = await hp.download(url, filename);
132
+ // console.log(file);
133
+ // }
134
+ // download();
135
+
136
+ // async function test() {
137
+ // var http = new Http();
138
+ // console.log("开始请求");
139
+ // var options = http.new_options({
140
+ // url: "http://www.hao123.com:8000/test?dd=123"
141
+ // });
142
+ // console.log(1, options);
143
+
144
+ // options = http.new_options({
145
+ // url: "www.hao123.com:8000/test?dd=123"
146
+ // });
147
+ // console.log(2, options);
148
+
149
+ // options = http.new_options({
150
+ // url: "www.hao123.com/test?dd=123"
151
+ // });
152
+ // console.log(3, options);
153
+
154
+ // var options = http.new_options({
155
+ // url: "http://www.hao123.com/test?dd=123"
156
+ // });
157
+ // console.log(4, options);
158
+
159
+ // var options = http.new_options({
160
+ // url: "http://www.hao123.com"
161
+ // });
162
+ // console.log(5, options);
163
+
164
+ // options = http.new_options({
165
+ // url: "https://www.hao123.com:8000"
166
+ // });
167
+ // console.log(6, options);
168
+
169
+ // options = http.new_options({
170
+ // url: "https://www.hao123.com?dd=123"
171
+ // });
172
+ // console.log(6, options);
173
+ // }
174
+
175
+ // async function test() {
176
+ // var http = new Http();
177
+ // var res = await http.get("https://www.hao123.com");
178
+ // console.log("结果", res.body);
179
+ // var res = await http.download('http://www.51sjk.com/Upload/Articles/1/0/8/8799_20200415005654483_0.jpg', "./demo.jpg");
180
+ // // console.log(res);
181
+
182
+ // // console.log("代理请求");
183
+ // // var http = new Http({
184
+ // // proxy: "http://127.0.0.1:10809"
185
+ // // });
186
+ // // var res = await http.get("https://www.binance.com/bapi/nft/v1/friendly/nft/nft-asset/asset-detail?nftInfoId=31849573");
187
+ // // console.log("结果", res.body);
120
188
  // }
121
189
 
122
- // test();
190
+ test();