我正在使用websockets模块,但它不支持通过我的公司代理进行客户端连接:
>>> import asyncio, websockets
>>> async def connect(uri):
... async with websockets.connect(uri) as websocket:
... pass
...
>>> asyncio.get_event_loop().run_until_complete(connect('ws://myhost.com/path/'))
....
ConnectionRefusedError: [Errno 10061] Connect call failed ('myhost.com', 80)
Run Code Online (Sandbox Code Playgroud)
但是,如果将curl 与我的http_proxy环境变量集一起使用,它会起作用:
$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Sec-WebSocket-Version: 13" -H "Sec-WebSocket-Key: MTIzNDEyMzQxMjM0MTIzNA==" http://myhost.com/path/
HTTP/1.1 101 Switching Protocols
Server: nginx/1.13.6
Date: Fri, 10 Nov 2017 14:51:00 GMT
Upgrade: websocket
Sec-WebSocket-Accept: s+CT5bkW5F3N2/5JUXrCPtLHn68=
Connection: Upgrade
Run Code Online (Sandbox Code Playgroud)
我最好的选择是什么?用于建立客户端 websocket 连接的其他模块?
我需要将代理与 HtmlAgilityPack 一起使用。我给出了我的应用程序的链接RefURL。之后我希望应用程序从代理地址获取 url。例如“101.109.44.157:8080”
我搜索并发现了这个:
WebClient wc = new WebClient();
wc.Proxy = new WebProxy(host,port);
var page = wc.DownloadString(url);
Run Code Online (Sandbox Code Playgroud)
并像这样使用它。
RefURL = new Uri(refLink.Text);
WebClient wc = new WebClient();
wc.Proxy = new WebProxy("101.109.44.157:8080");
var page = wc.DownloadString(RefURL);
RefURL.ToString();
HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load(RefURL.ToString());
Run Code Online (Sandbox Code Playgroud)
但它不起作用!
我正在尝试使用nodejitsu/node-http-proxy制作 HTTP 代理,并且我使用此方法来捕获代理响应
\n\nproxy.on(\'proxyRes\', function (proxyRes, req, res) {\n var body = new Buffer(\'\');\n proxyRes.on(\'data\', function (data) {\n body = Buffer.concat([body, data]);\n });\n proxyRes.on(\'end\', function () {\n body = body.toString();\n console.log("res from proxied server:", body);\n });\n});\nRun Code Online (Sandbox Code Playgroud)\n\n在这里我能够得到响应,但它在缓冲区中。所以我尝试了很多方法将我的响应转换为字符串格式
\n\n但我得到了这个\nres from proxied server: \xef\xbf\xbdAo\xef\xbf\xbd@\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdj/\xef\xbf\xbdRc\xef\xbf\xbdI\\\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd[\xc9\xa1\xef\xbf\xbdP\xef\xbf\xbd^O\xef\xbf\xbdm\xef\xbf\xbd\xef\xbf\xbdhg\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd"\xef\xbf\xbd\xc4\x89\xef\xbf\xbdJ\xef\xbf\xbdi\xef\xbf\xbdy\xef\xbf\xbd\xef\xbf\xbdg\xef\xbf\xbd\xef\xbf\xbdK\xef\xbf\xbd\xef\xbf\xbdy\xef\xbf\xbd\xef\xbf\xbd%z\xef\xbf\xbd\n\xef\xbf\xbdj:\xef\xbf\xbdJ\xef\xbf\xbd5/\xef\xbf\xbdg]\xef\xbf\xbdB\xef\xbf\xbd\xef\xbf\xbd
如何解决这个问题
\n\n提前致谢
\n我们计划在我的项目中使用 Envoy,所以我开始摆弄 Envoy github 上提供的简单示例,并且我在公司代理方面遇到了困难。
我尝试的第一件事非常简单,通过 Envoy 提供一个网站 www.onisep.fr(我特意选择了一个没有 HTTPS 的网站)。
我的单个 Envoy docker 镜像:
FROM envoyproxy/envoy:latest
ENV HTTP_PROXY http://mycompany.proxy:8080
ENV HTTPS_PROXY http://mycompany.proxy:8080
CMD apt-get update && apt-get -y install curl -y
CMD /usr/local/bin/envoy -c /etc/front-envoy.yaml --service-cluster front-proxy --log-level trace
Run Code Online (Sandbox Code Playgroud)
注意:注意代理配置
我的特使配置:
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 80
filter_chains:
- filters:
- name: envoy.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: simple_route
domains:
- "*"
routes:
- match:
prefix: "/" …Run Code Online (Sandbox Code Playgroud) 我有 2 个快递服务器:
两者都可以使用以下方式在本地访问:
http://localhost:3000/news
http://localhost:3001/stock
我的目标:
从代理服务器访问两个 Express 服务器端点http://localhost:8008
我的问题:
我只能到达第一个api1的端点
任何帮助将不胜感激 :)
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const api1 = createProxyMiddleware({
target: 'http://localhost:3000'
});
const api2 = createProxyMiddleware({
target: 'http://localhost:3001'
});
const app = express();
app.use(api1);
app.use(api2);
app.listen(8008);
Run Code Online (Sandbox Code Playgroud)
**编辑1:
我尝试了一下,它适用于api1端点,但不适用于api2端点。
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const apiProxy = createProxyMiddleware('/', {
target: 'http://localhost:3000'
});
const apiProxytwo = createProxyMiddleware('/', {
target: …Run Code Online (Sandbox Code Playgroud) 我尝试使用代理 json 将 Angular 与 Spring MVC 连接。我尝试了多次,但总是抛出 404 错误。
GET http://localhost:4200/api/v1/employees 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)
这是我的代码块的片段。提前致谢。
代理.conf.json
{
"/api/v1": {
"target": "http://localhost:8080",
"secure": false,
"changeOrigin": true
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序组件.ts
getAllEmployees() {
this._http.get('/api/v1/employees').subscribe(
data => {
this.result = data.toString();
},
error => {
});
}
Run Code Online (Sandbox Code Playgroud)
控制器
@RestController
@RequestMapping(value = "/api/v1")
public class HomeController {
@RequestMapping("/employees")
public String getDisplayMessage() {
return "Hi Welcome!!!";
}
}
Run Code Online (Sandbox Code Playgroud)
网络.xml
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
假设单击 html 按钮时调用 getAllEmployee() 方法。
我可以收到消息“您好,欢迎!!!” ,当我尝试http://localhost:8080/spring-mvc-demo/api/v1/employees
有人可以告诉我哪里编码错误吗?
spring-mvc http-proxy apache-httpclient-4.x spring-boot angular
我正在使用一个 HTTP 请求库,它可以使用http.Agent实例来通过特定代理路由您的请求。让我举一个例子:
const SocksProxyAgent = require('socks-proxy-agent')
const HttpProxyAgent = require('http-proxy-agent') // not used
const axios = require('axios')
// requires Tor service to be running
const torProxyAgent = new SocksProxyAgent('socks://circuit1@127.0.0.1:9050')
// not used
const otherProxyAgent = new HttpProxyAgent('http://admin:1234@localhost:8888')
const axiosConfig = {
httpsAgent: torProxyAgent,
httpAgent: torProxyAgent
}
const axiosInstance = axios.create(axiosConfig)
axiosInstance.get('https://ifconfig.io/ip')
.then(res => {
console.log('Public IP address:', res.data)
}).catch(err => {
console.log(err)
})
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我指定了多个代理 (torProxyAgent和otherProxyAgent),但我只能使用一个。
因此,我正在寻找一种超级代理,我可以将其传递给我的 HTTP 请求库,然后该超级代理通过将所有请求路由到第一个代理,然后通过第二个代理,然后将任意数量的普通代理链接在一起。到第三个,依此类推……
这可能吗?有现成的解决方案吗?
是否有一种方法可以使用Proxy类创建一个假代理,将所有方法调用传递给一个代理,然后传递给第二个代理?
编辑: …
我使用Google HTTP Client Library for Java来制作简单的JSON请求并解析响应.当我不通过代理时,它运作良好.但现在我想允许我的用户在我的应用程序中使用代理(带身份验证)功能.我查看了HttpTransport,HttpRequestFactory和HttpRequestInitializer类没有任何成功.
到目前为止,我只略微修改了这些示例(主要是它删除了不必要的代码).那么我在代码中添加了代理设置?
static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
static final JsonFactory JSON_FACTORY = new JacksonFactory();
<T> T get(String url, Class<T> type) throws IOException {
HttpRequestFactory requestFactory =
HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) {
request.setParser(new JsonObjectParser(JSON_FACTORY));
}
});
HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(url));
return request.execute().parseAs(type);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用http-proxy代理对REST API的调用,但它会不断返回404代码.
这是对我的API的示例调用:http://petrpavlik.apiary-mock.com/notes它返回一些JSON数据.
这就是我的服务器代码:
var httpProxy = require('http-proxy');
var proxy = httpProxy.createServer({
target:'http://petrpavlik.apiary-mock.com'
});
proxy.listen(8005);
proxy.on('error', function (err, req, res) {
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end('Something went wrong. And we are reporting a custom error message.');
});
proxy.on('proxyRes', function (res) {
console.log('RAW Response from the target', JSON.stringify(res.headers, true, 2));
});
Run Code Online (Sandbox Code Playgroud)
当我尝试使用我的代理调用相同的请求时,这就是我得到的.
Petrs-MacBook-Air-2:~ petr$ curl -v 127.0.0.1:8005/notes
* About to connect() to 127.0.0.1 port 8005 (#0)
* Trying 127.0.0.1...
* Adding handle: conn: 0x7f977280fe00
* Adding …Run Code Online (Sandbox Code Playgroud) 我希望使用nn包作为火炬框架.我从github下载并制作了火炬.但是,当我现在这样做:
luarocks install nn
Run Code Online (Sandbox Code Playgroud)
我得克隆成'nn'致命:无法连接到github.com错误.我的代理服务器配置为wget和github.两者都很好.我在线查看,只能找到这个,所以我找了config.lua,但有很多,所以我添加到这一切:
proxy="proxy@port"
Run Code Online (Sandbox Code Playgroud)
但是,luarocks仍然不起作用.请提出建议.
http-proxy ×10
node.js ×3
express ×2
proxy ×2
angular ×1
c# ×1
docker ×1
envoyproxy ×1
http ×1
java ×1
javascript ×1
luarocks ×1
python-3.x ×1
socks ×1
spring-boot ×1
spring-mvc ×1
websocket ×1