Tôi có một ExternalServe (chạy trên Localhost) Khi tôi sử dụng trình duyệt yêu cầu:NodeJS - Cách tải tệp xuống qua Yêu cầu?
localhost: 2013/ExternalServer/getfilebyname filename = getStatus.json
Sau đó trình duyệt tải getStatus.json để tải xuống thư mục.
Trong dự án NodeJS của tôi, tôi muốn tải về tập tin getStatus.json và tôi đã thực hiện:
download.js
var http = require('http');
var fs = require('fs');
function getFile(){
var file = fs.createWriteStream("./../lib/user.json");
var req = http.get("http://localhost:2013/ExternalServer/getfilebyname?filename=getStatus.json", function(res) {
res.pipe(file);
});
}
getFile();
nhưng khi tôi chạy: nút download.js sự trở lại hệ thống
<html><head><title>Apache Tomcat/8.0.0-RC1 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>This request requires HTTP authentication.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/8.0.0-RC1</h3></body></html>
Cách khắc phục?
Quan trọng nhất
nếu tài khoản và mật khẩu của tôi cả hai đều là "tomcat", sau đó 'Authorization': ' Basic '+ new Buffer ("tomcat" +': '+ "tomcat) .toString (' base64 ')? – alongquan
vâng ... dường như đang hoạt động. –
Thansk U rất nhiều, đã thành công ...: D – alongquan