我正在尝试使用 Node.js(使用请求 npm 模块)向第三方(不受我控制)Web 服务器发送 HTTP GET 请求,并被服务器重定向到日志-在页面中。它拒绝发送页面,因为我没有登录。
由于重定向不能发生在客户端(我正在请求页面,而不是解析它),我不明白 Web 服务器如何检查本地数据或 cookie 以查看是否在决定是否向我发送页面之前,我(我的 HTTP GET 请求)已登录。
我的问题
在响应请求之前,网络服务器可以通过什么方式检查是否在现有页面上重定向 GET 请求?
我的代码
var request = require('request');
function checkUsername(username) {
request({
uri : "http://www.kongregate.com/accounts/" + username + "/recently-played",
method : "GET",
timeout : 10000,
//in order to avoid being redirected to the login page, I've used:
followRedirect : false,
maxRedirects : 0
}, function(error, response, body) {
if (error)
console.log("Player does not exist");
else {
console.log("Player exists!");
}
}
});
}
checkUsername("jonathan_t0dd");
这可以避免成功的重定向,但可以提供 html:
<html><body>You are being <a href="http://www.kongregate.com/session/new">redirected</a>.</body></html>
我想以一种可能让我了解如何向服务器提供成功提供我所请求的 Assets 所需的任何数据的方式来理解这种情况。
最佳答案
I don't understand how the web server can be checking local data or cookies to see whether or not I (my HTTP GET request) is logged in before deciding whether or not to send me the page.
Cookie 会随每个 HTTP 请求发送到服务器。这就是cookies的意义所在。所以,几乎可以肯定,只是查看cookie。
关于javascript - Web 服务器可以在响应请求之前以什么方式检查是否在现有页面上重定向 GET 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25889112/