本来想使用xampp代理的,搞了半天太麻烦了。所以使用nodejs代理做,方便很多,具体看一下代码:
var express = require(“express”);
var app = express();
var proxy = require(“http-proxy-middleware”);
var cors = require(“cors”);
var apiproxy = [
proxy(“/”, {
target: “https://api.douban.com”,
changeOrigin: true
})
];
app.use(cors());
app.use((req, res, next) => {
req.headers = {
“accept”: “*/*”,
“accept-encoding”: “gzip, deflate, sdch, br”,
“accept-language”: “zh-CN,zh;q=0.8”,
“cache-control”: “no-cache”,
“connection”: “keep-alive”,
“host”: “localhost:5000”,
“origin”: “http://localhost:8080”,
“pragma”: “no-cache”,
“referer”: “http://localhost:8080/”,
“user-agent”: “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36”
}
next();
});
app.use((req, res, next) => {
console.log(req.headers.referer);
next();
})
app.use(apiproxy);
app.listen(8888, () => {
console.log(“port on 8888”)
});
访问方式就直接使用:http://localhost:8888/v2/movie/in_theaters形式访问就可以了。参数和其他地址正常无变化。只是将api.douban.com换成了localhost:8888