Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  92] [ 1]  / answers: 1 / hits: 22568  / 11 Years ago, sun, august 18, 2013, 12:00:00

I have a ExternalServe (running on Localhost)
When I using Browser to request:




localhost:2013/ExternalServer/getfilebyname?filename=getStatus.json




Then browser downloaded getStatus.json to Download Folder.



In my NodeJS project, I want to download getStatus.json file and I made:



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();


but when i run: node download.js the system return



<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>


How to fix it?



Best regard


More From » json

 Answers
4

You are getting the following error response:




This request requires HTTP authentication




Suggesting to add the Authorization information in header. Like:



var options = {
host: 'localhost',
port: 2013,
path: '/ExternalServer/getfilebyname?filename=getStatus.json',
headers: {
'Authorization': 'Basic ' + new Buffer(uname + ':' + pword).toString('base64')
}
};

request = http.get(options, function(res) {
res.pipe(file);
});


in case of proxy, you can use the following header instead:



Proxy-Authorization

[#76296] Thursday, August 15, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
makaylahk

Total Points: 166
Total Questions: 94
Total Answers: 117

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
;