mm_https 1.6.4 → 1.6.5
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/README.md +25 -1
- package/index.js +4 -2
- package/package.json +1 -1
- package/test.js +5 -3
package/README.md
CHANGED
|
@@ -13,7 +13,9 @@ npm install mm_https
|
|
|
13
13
|
### 初始化
|
|
14
14
|
|
|
15
15
|
```javascript
|
|
16
|
-
const
|
|
16
|
+
const {
|
|
17
|
+
Http
|
|
18
|
+
} = require('mm_https');
|
|
17
19
|
|
|
18
20
|
// 基本初始化
|
|
19
21
|
const http = new Http();
|
|
@@ -40,6 +42,10 @@ const httpWithConfig = new Http({
|
|
|
40
42
|
### GET请求
|
|
41
43
|
|
|
42
44
|
```javascript
|
|
45
|
+
const {
|
|
46
|
+
Http
|
|
47
|
+
} = new Http();
|
|
48
|
+
|
|
43
49
|
const http = new Http();
|
|
44
50
|
|
|
45
51
|
// 基本GET请求
|
|
@@ -67,6 +73,10 @@ async function getWithCookie() {
|
|
|
67
73
|
### POST请求
|
|
68
74
|
|
|
69
75
|
```javascript
|
|
76
|
+
const {
|
|
77
|
+
Http
|
|
78
|
+
} = new Http();
|
|
79
|
+
|
|
70
80
|
const http = new Http();
|
|
71
81
|
|
|
72
82
|
// JSON格式POST请求
|
|
@@ -101,6 +111,10 @@ async function postWithHeadersAndCookie() {
|
|
|
101
111
|
### 文件下载
|
|
102
112
|
|
|
103
113
|
```javascript
|
|
114
|
+
const {
|
|
115
|
+
Http
|
|
116
|
+
} = new Http();
|
|
117
|
+
|
|
104
118
|
const http = new Http();
|
|
105
119
|
|
|
106
120
|
// 基本文件下载
|
|
@@ -134,11 +148,21 @@ async function downloadWithHeaders() {
|
|
|
134
148
|
### Cookie管理
|
|
135
149
|
|
|
136
150
|
```javascript
|
|
151
|
+
const {
|
|
152
|
+
Http
|
|
153
|
+
} = new Http();
|
|
154
|
+
|
|
137
155
|
const http = new Http();
|
|
138
156
|
|
|
139
157
|
// 设置Cookie
|
|
140
158
|
http.setCookie('session=abc123; user=john');
|
|
141
159
|
|
|
160
|
+
// 或者通过对象设置多个Cookie
|
|
161
|
+
http.setCookie({
|
|
162
|
+
'session': 'abc123',
|
|
163
|
+
'user': 'john'
|
|
164
|
+
});
|
|
165
|
+
|
|
142
166
|
// 获取当前所有Cookie
|
|
143
167
|
const cookieString = http.getCookie();
|
|
144
168
|
$.log.debug('当前Cookie:', cookieString);
|
package/index.js
CHANGED
|
@@ -450,11 +450,13 @@ Http.prototype.clear = function () {
|
|
|
450
450
|
this._cookies = {};
|
|
451
451
|
};
|
|
452
452
|
|
|
453
|
-
if (global.$) {
|
|
453
|
+
if (global.$ && !$.Http) {
|
|
454
454
|
$.Http = Http;
|
|
455
455
|
}
|
|
456
456
|
|
|
457
457
|
/**
|
|
458
458
|
* 导出构造函数
|
|
459
459
|
*/
|
|
460
|
-
module.exports =
|
|
460
|
+
module.exports = {
|
|
461
|
+
Http
|
|
462
|
+
};
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* 用于npm发布前的功能验证
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const {
|
|
7
|
+
Http
|
|
8
|
+
} = require('./index.js');
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* 基础HTTP请求测试
|
|
@@ -97,7 +98,8 @@ async function testErrorHandling() {
|
|
|
97
98
|
// 设置较短的超时时间,避免长时间等待
|
|
98
99
|
const timeoutHttp = new Http();
|
|
99
100
|
// 使用不存在的域名进行测试
|
|
100
|
-
await timeoutHttp.get('http://nonexistent-domain-12345.test');
|
|
101
|
+
const res = await timeoutHttp.get('http://nonexistent-domain-12345.test');
|
|
102
|
+
console.log('GET响应状态码:', res.status, '响应消息:', res.message, '响应内容:', res.body);
|
|
101
103
|
console.log('⚠️ 不存在的域名测试 - 请求可能被重定向或超时');
|
|
102
104
|
} catch (err) {
|
|
103
105
|
console.log('不存在的域名处理正确:', err.message);
|