贊助商連結

Nodejs fake referer

Nodejs 要假造一個 referer 實在太簡單了

request 抓網頁,再加個 headers 就搞定了

1
2
3
4
5
request({uri:'http://localhost:3000/users', headers: {referer: 'http://localhost:3000/'}}, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
});

完整的程式碼如下

app2.jsview raw
1
2
3
4
5
6
var request = require('request');
request({uri:'http://localhost:3000/users', headers: {referer: 'http://localhost:3000/'}}, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
});