Ich versuche, eine Webseite zum Download und ich schrieb den folgenden Code:Bad Anforderungsfehler, bei dem Versuch, eine Web-Seite zum Download
var https = require("https");
var options = {
hostname : "stackoverflow.com",
port : 443,
path : "questions/18867185/socket-hang-up-error-during-request",
method : "GET"
};
var req = https.request(options, function(res) {
var responseBody ="";
console.log("Response from server started..\n");
console.log("Status Code : " + res.statusCode + "\n");
console.log("\n\n\n Headers : %j", res.headers);
res.setEncoding("UTF-8");
res.on("data",function(data) {
console.log("--Data-- " + data);
responseBody += data;
});
res.on("end",function() {
console.log("Download complete\n");
console.log(responseBody);
});
});
req.on("error",function(err) {
console.log("Error reportted " + err);
});
req.end();
Aber ich bekomme immer die 400
| Bad Request
Fehler! Was könnte der Grund dafür sein?
Antwort:
Response from server started..
Status Code : 400
Headers : {"server":"cloudflare-nginx","date":"Wed, 25 May 2016 11:05:23 GMT","content-type":"text/html","content-length":"177","connection":"close"}
--Data-- <html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare-nginx</center>
</body>
</html>
Download complete
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare-nginx</center>
</body>
</html>