什么时候应该在 HTTP 代理服务器上使用 CONNECT 和 GET HTTP 方法? [英] When should one use CONNECT and GET HTTP methods at HTTP Proxy Server?

查看:24
本文介绍了什么时候应该在 HTTP 代理服务器上使用 CONNECT 和 GET HTTP 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 WebClient 库.现在我正在实现一个代理功能,所以我正在做一些研究,我看到了一些使用 CONNECT 方法来请求 URL 的代码.

I'm building a WebClient library. Now I'm implementing a proxy feature, so I am making some research and I saw some code using the CONNECT method to request a URL.

但是在我的网络浏览器中检查它,它不使用 CONNECT 方法而是调用 GET 方法.

But checking it within my web browser, it doesn't use the CONNECT method but calls the GET method instead.

所以我很困惑.我什么时候应该同时使用这两种方法?

So I'm confused. When I should use both methods?

推荐答案

CONNECT 请求促使您的代理建立到远程端点的 HTTP 隧道.通常它用于 SSL 连接,尽管它也可以用于 HTTP(用于代理链接和隧道)

A CONNECT request urges your proxy to establish an HTTP tunnel to the remote end-point. Usually is it used for SSL connections, though it can be used with HTTP as well (used for the purposes of proxy-chaining and tunneling)

CONNECT www.google.com:443 

以上行在端口 443 上打开了从您的代理到 www.google.com 的连接.此后,客户端发送的内容由代理转发到 www.google.com:443.

The above line opens a connection from your proxy to www.google.com on port 443. After this, content that is sent by the client is forwarded by the proxy to www.google.com:443.

如果用户尝试检索页面 http://www.google.com,代理可以发送完全相同的请求并代表他为他检索回复.

If a user tries to retrieve a page http://www.google.com, the proxy can send the exact same request and retrieve response for him, on his behalf.

使用 SSL(HTTPS),只有两个远程端点理解请求,代理无法解密它们.因此,它所做的就是使用 CONNECT 打开该隧道,并让两个端点(网络服务器和客户端)直接相互通信.

With SSL(HTTPS), only the two remote end-points understand the requests, and the proxy cannot decipher them. Hence, all it does is open that tunnel using CONNECT, and lets the two end-points (webserver and client) talk to each other directly.

代理链:

如果您要链接 2 个代理服务器,则这是要发出的请求的顺序.

If you are chaining 2 proxy servers, this is the sequence of requests to be issued.

GET1 is the original GET request (HTTP URL)
CONNECT1 is the original CONNECT request (SSL/HTTPS URL or Another Proxy)

User Request ==CONNECT1==> (Your_Primary_Proxy ==CONNECT==> AnotherProxy-1 ... ==CONNECT==> AnotherProxy-n) ==GET1(IF is http)/CONNECT1(IF is https)==> Destination_URL

这篇关于什么时候应该在 HTTP 代理服务器上使用 CONNECT 和 GET HTTP 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆