使用http-node-proxy创建代理

时间:2019-06-06 03:56:44

标签: node.js curl proxy

我正在尝试为http://proxy_target.com.ar开发节点本地代理,到目前为止,这是我所尝试的

const http = require('http')
const httpProxy = require('http-proxy')

var proxyOptions = {
  target: 'http://proxy_target.com.ar',
}

var proxy = httpProxy.createProxyServer({})

var server = http.createServer(function (req, res) {
  proxy.web(req, res, proxyOptions);
});

console.log("listening on port 5050")
server.listen(5050);

现在,如果我向proxy_target网站发出卷发,就会得到:

λ curl -v -i -X GET http://proxy_target.com.ar/EEServices/consulta?wsdl

> GET /EEServices/consulta?wsdl HTTP/1.1
> Host: proxy_target.com.ar
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 06 Jun 2019 00:14:17 -0300
< Server: Mule Core/3.4.0
< Content-Type: text/xml

但是如果我尝试对代理服务器执行相同操作:

λ curl -v -i -X GET localhost:5050/EEServices/consulta.wsdl
*   Trying ::1...
* Connected to localhost (::1) port 5050 (#0)
> GET /EEServices/consulta.wsdl HTTP/1.1
> Host: localhost:5050
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
server: Apache-Coyote/1.1
content-type: text/html;charset=utf-8
content-language: en
content-length: 999
date: Thu, 06 Jun 2019 03:11:15 GMT
connection: close

<html><head>
<title>Apache Tomcat/7.0.69 - Error report</title>
</head>
<body>
<h1>HTTP Status 404 - /EEServices/consulta.wsdl</h1>
<u>/EEServices/consulta.wsdl</u>
<u>The requested resource is not available.</u>
<h3>Apache Tomcat/7.0.69</h3>
</body></html>*
Closing connection 0

我想念什么吗?

0 个答案:

没有答案