我第一次尝试用我的简单 Twitter tweeter 实现 Node http 代理。我以前从未使用过这个,并尝试按照文档(https://github.com/nodejitsu/node-http-proxy)进行操作,但没有成功。有人能指出我正确的方向吗?另外,可以在Mac上本地运行吗?谢谢
var express = require('express');
var app = express();
var port = 8300;
var twitter = require('twitter');
var twit = new twitter({ keys and stuff })
var http = require('http'),
httpProxy = require('http-proxy');
twit.post('statuses/update', {status: "Hello world!"}
//this works
httpProxy.createProxyServer({target:'http://localhost:3000'}).listen(3000);
// Create your target server--- WHat exactly does this mean??
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(3000);
最佳答案
您不应使用此库来代理您的请求。该库用于制作您自己的代理服务器。看example如何通过 twitter
lib 使用代理
关于javascript - Node -HTTP-代理错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38319391/