mm_https 1.4.1 → 1.4.6
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.
- package/index.js +27 -17
- package/package.json +37 -37
- package/test.js +14 -4
package/index.js
CHANGED
|
@@ -46,10 +46,11 @@ function getInfo(url) {
|
|
|
46
46
|
*/
|
|
47
47
|
class Http {
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* 构造函数
|
|
50
50
|
* @constructor
|
|
51
|
+
* @param {Object} config 配置参数
|
|
51
52
|
*/
|
|
52
|
-
constructor() {
|
|
53
|
+
constructor(config) {
|
|
53
54
|
/**
|
|
54
55
|
* 存储上次请求
|
|
55
56
|
*/
|
|
@@ -63,6 +64,25 @@ class Http {
|
|
|
63
64
|
* 获取的编码方式
|
|
64
65
|
*/
|
|
65
66
|
this.encoding = 'utf-8';
|
|
67
|
+
|
|
68
|
+
this.config = Object.assign({
|
|
69
|
+
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',
|
|
72
|
+
'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"',
|
|
75
|
+
'sec-ch-ua-mobile': '?0',
|
|
76
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
77
|
+
'sec-fetch-dest': 'document',
|
|
78
|
+
'sec-fetch-mode': 'navigate',
|
|
79
|
+
'sec-fetch-site': 'none',
|
|
80
|
+
'sec-fetch-user': '?1',
|
|
81
|
+
'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'
|
|
83
|
+
},
|
|
84
|
+
rejectUnauthorized: false
|
|
85
|
+
}, config)
|
|
66
86
|
}
|
|
67
87
|
}
|
|
68
88
|
|
|
@@ -104,23 +124,13 @@ Http.prototype.option = function(method, url, cookie) {
|
|
|
104
124
|
port,
|
|
105
125
|
path
|
|
106
126
|
} = getInfo(url);
|
|
107
|
-
var op = {
|
|
127
|
+
var op = Object.assign({}, this.config, {
|
|
108
128
|
url: url,
|
|
109
129
|
hostname: host,
|
|
110
130
|
path: path,
|
|
111
131
|
port: port,
|
|
112
|
-
method: method
|
|
113
|
-
|
|
114
|
-
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
|
|
115
|
-
'Accept-Encoding': 'gzip, deflate',
|
|
116
|
-
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
117
|
-
'Cache-Control': 'max-age=0',
|
|
118
|
-
'Connection': 'keep-alive',
|
|
119
|
-
'Upgrade-Insecure-Requests': '1',
|
|
120
|
-
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
|
|
121
|
-
'X-Requested-With': 'XMLHttpRequest'
|
|
122
|
-
}
|
|
123
|
-
};
|
|
132
|
+
method: method
|
|
133
|
+
});
|
|
124
134
|
if (cookie) {
|
|
125
135
|
op.cookie = cookie;
|
|
126
136
|
} else if (this.cookie) {
|
|
@@ -173,7 +183,7 @@ Http.prototype.req = function(options, param) {
|
|
|
173
183
|
}
|
|
174
184
|
resolve({
|
|
175
185
|
headers: res.headers,
|
|
176
|
-
binary:
|
|
186
|
+
binary: decoded,
|
|
177
187
|
body: body
|
|
178
188
|
});
|
|
179
189
|
}
|
|
@@ -190,7 +200,7 @@ Http.prototype.req = function(options, param) {
|
|
|
190
200
|
}
|
|
191
201
|
resolve({
|
|
192
202
|
headers: res.headers,
|
|
193
|
-
binary:
|
|
203
|
+
binary: decoded,
|
|
194
204
|
body: body
|
|
195
205
|
});
|
|
196
206
|
}
|
package/package.json
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "mm_https",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"description": "这是超级美眉http请求帮助类模块,可自动补充cookie,实现模拟登录,通讯",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "node test.js"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/qiuwenwu/mm_https.git"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"myhttp",
|
|
15
|
-
"async",
|
|
16
|
-
"await",
|
|
17
|
-
"promise",
|
|
18
|
-
"add",
|
|
19
|
-
"del",
|
|
20
|
-
"set",
|
|
21
|
-
"get",
|
|
22
|
-
"query",
|
|
23
|
-
"run",
|
|
24
|
-
"exec"
|
|
25
|
-
],
|
|
26
|
-
"author": "邱文武",
|
|
27
|
-
"license": "ISC",
|
|
28
|
-
"bugs": {
|
|
29
|
-
"url": "https://github.com/qiuwenwu/mm_https/issues"
|
|
30
|
-
},
|
|
31
|
-
"homepage": "https://github.com/qiuwenwu/mm_https#readme",
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"iconv-lite": "^0.5.0",
|
|
34
|
-
"mm_expand": "^1.4.
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {}
|
|
37
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "mm_https",
|
|
3
|
+
"version": "1.4.6",
|
|
4
|
+
"description": "这是超级美眉http请求帮助类模块,可自动补充cookie,实现模拟登录,通讯",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node test.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/qiuwenwu/mm_https.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"myhttp",
|
|
15
|
+
"async",
|
|
16
|
+
"await",
|
|
17
|
+
"promise",
|
|
18
|
+
"add",
|
|
19
|
+
"del",
|
|
20
|
+
"set",
|
|
21
|
+
"get",
|
|
22
|
+
"query",
|
|
23
|
+
"run",
|
|
24
|
+
"exec"
|
|
25
|
+
],
|
|
26
|
+
"author": "邱文武",
|
|
27
|
+
"license": "ISC",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/qiuwenwu/mm_https/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/qiuwenwu/mm_https#readme",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"iconv-lite": "^0.5.0",
|
|
34
|
+
"mm_expand": "^1.4.7"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {}
|
|
37
|
+
}
|
package/test.js
CHANGED
|
@@ -103,10 +103,20 @@ var fs = require("fs");
|
|
|
103
103
|
|
|
104
104
|
async function download(){
|
|
105
105
|
var hp = new Http();
|
|
106
|
-
var url = "
|
|
107
|
-
"
|
|
108
|
-
|
|
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);
|
|
109
111
|
console.log(file);
|
|
110
112
|
}
|
|
113
|
+
download();
|
|
111
114
|
|
|
112
|
-
|
|
115
|
+
// async function test(){
|
|
116
|
+
// var hp = new Http();
|
|
117
|
+
// var url = "https://weibo.com/p/1003061669879400";
|
|
118
|
+
// var res = await hp.get(url);
|
|
119
|
+
// console.log(res);
|
|
120
|
+
// }
|
|
121
|
+
|
|
122
|
+
// test();
|