mm_https 1.4.7 → 1.4.8
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 +6 -5
- package/package.json +1 -1
- package/test.js +20 -20
package/index.js
CHANGED
|
@@ -95,7 +95,8 @@ Http.prototype.http_options = function(options) {
|
|
|
95
95
|
body,
|
|
96
96
|
headers,
|
|
97
97
|
method,
|
|
98
|
-
cookie
|
|
98
|
+
cookie,
|
|
99
|
+
type
|
|
99
100
|
} = options;
|
|
100
101
|
var protocol = url.left(":/") || 'http';
|
|
101
102
|
// 移除协议头 取端口号
|
|
@@ -115,6 +116,7 @@ Http.prototype.http_options = function(options) {
|
|
|
115
116
|
protocol,
|
|
116
117
|
hostname,
|
|
117
118
|
body,
|
|
119
|
+
type,
|
|
118
120
|
port: Number(port),
|
|
119
121
|
path: path.indexOf("/") === 0 ? path : "/" + path,
|
|
120
122
|
method: method || "GET",
|
|
@@ -243,7 +245,6 @@ Http.prototype.request = function(options) {
|
|
|
243
245
|
resolve({
|
|
244
246
|
status: 200,
|
|
245
247
|
headers,
|
|
246
|
-
binary: buffer,
|
|
247
248
|
body: body
|
|
248
249
|
});
|
|
249
250
|
});
|
|
@@ -303,6 +304,7 @@ Http.prototype.post = async function(url, body, headers, type, cookie) {
|
|
|
303
304
|
method: "POST",
|
|
304
305
|
url,
|
|
305
306
|
body,
|
|
307
|
+
type,
|
|
306
308
|
headers,
|
|
307
309
|
cookie
|
|
308
310
|
});
|
|
@@ -318,10 +320,9 @@ Http.prototype.post = async function(url, body, headers, type, cookie) {
|
|
|
318
320
|
* @return {String} 成功返回保存路径,失败返回null
|
|
319
321
|
*/
|
|
320
322
|
Http.prototype.download = async function(url, filename, auto, headers, cookie) {
|
|
321
|
-
this.encoding = "binary";
|
|
322
323
|
var res = await this.get(url, headers, cookie);
|
|
323
324
|
var file = null;
|
|
324
|
-
if (res.
|
|
325
|
+
if (res.body) {
|
|
325
326
|
if (auto) {
|
|
326
327
|
var arr = url.split('/');
|
|
327
328
|
var fullname = arr[arr.length - 1];
|
|
@@ -341,7 +342,7 @@ Http.prototype.download = async function(url, filename, auto, headers, cookie) {
|
|
|
341
342
|
file = filename;
|
|
342
343
|
}
|
|
343
344
|
if (file) {
|
|
344
|
-
var length = await fs.writeFileSync(file, res.
|
|
345
|
+
var length = await fs.writeFileSync(file, res.body, "binary");
|
|
345
346
|
if (length == 0) {
|
|
346
347
|
file = null;
|
|
347
348
|
}
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -75,23 +75,23 @@ var fs = require("fs");
|
|
|
75
75
|
// }
|
|
76
76
|
|
|
77
77
|
// 测试
|
|
78
|
-
async function test() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
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, 'json');
|
|
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
95
|
|
|
96
96
|
// async function test () {
|
|
97
97
|
// var hp = new Http();
|
|
@@ -101,9 +101,9 @@ async function test() {
|
|
|
101
101
|
|
|
102
102
|
// async function test() {
|
|
103
103
|
// var hp = new Http();
|
|
104
|
-
// hp.encoding = "binary";
|
|
105
104
|
// var res = await hp.get('http://localhost:8080/dev/img/logo_gray.png');
|
|
106
|
-
//
|
|
105
|
+
// console.log(res);
|
|
106
|
+
// fs.writeFile("./logonew.png", res.body, "binary", function(err) {
|
|
107
107
|
// if (err) {
|
|
108
108
|
// console.log("下载失败");
|
|
109
109
|
// }
|
|
@@ -187,4 +187,4 @@ async function test() {
|
|
|
187
187
|
// // console.log("结果", res.body);
|
|
188
188
|
// }
|
|
189
189
|
|
|
190
|
-
test();
|
|
190
|
+
// test();
|