通过代理服务器访问HTTPS站点 [英] Accessing HTTPS site through Proxy Server

查看:1197
本文介绍了通过代理服务器访问HTTPS站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在添加代码以使用代理服务器来访问Internet。
从正常(HTTP)位置请求文件时,代码工作正常,但在访问安全位置(HTTPS)时不起作用。

I am adding code to use a proxy server to access the Internet. The code works fine when requesting a file from a normal (HTTP) location, but does not work when accessing a secure location (HTTPS).

这是工作得很好的代码:

This is the code that works just fine:

URL = "http://UnSecureSite.net/file.xml"
Dim wr As HttpWebRequest = CType(WebRequest.Create(URL), HttpWebRequest)
Dim proxy As System.Net.IWebProxy
proxy = WebRequest.GetSystemWebProxy
wr.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)

// (more work here)

一旦我将URL更改为HTTPS,我就会将407返回给我。

As soon as I change the URL to go to HTTPS, I get a 407 returned to me.

任何人都有任何想法?

URL = "https://SecureSite.net/file.xml"
Dim wr As HttpWebRequest = CType(WebRequest.Create(URL), HttpWebRequest)
Dim proxy As System.Net.IWebProxy
proxy = WebRequest.GetSystemWebProxy
wr.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim myCache As New CredentialCache()
myCache.Add(New Uri("https://SecureSite.net"), "Basic", New NetworkCredential(UserName, Password))
wr.Credentials = myCache
Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)

// (more work here)


推荐答案

通过网络代理的HTTPS请求与标准的HTTP请求不同。常规HTTP请求将使用GET方法。但是,HTTPS请求需要使用CONNECT方法。然后,代理将仅建立到服务器的隧道。后续消息将通过代理隧道直接在客户端和服务器之间发送。代理人无法解释其间流动的数据。

A HTTPS request through a web-proxy is different from a standard HTTP request. A regular HTTP request will use the GET method. However, a HTTPS request needs to use a CONNECT method. Then, the proxy will merely establish a tunnel to the server. Subsequent messages will be sent directly between the client and the server through the proxy tunnel. The proxy has no way of interpreting the data flowing in between.

在正常情况下:

Client -+- [CONNECT] ---> Proxy --- [DIRECT TCP] -+-> Server
        |                   |                     |
        +-------------[ENCRYPTED TCP]-------------+

我对VB代码不太熟悉,不知道是不是发生了什么。但是,我怀疑它不是。最简单的检查方法是拦截发送给代理的消息。确保它以CONNECT ...开头。

I am not familiar enough with the VB code to know if that is what is happening. However, I suspect that it is not. The easiest way to check is to intercept the message being sent to the proxy. Make sure that it begins with a "CONNECT ...".

这篇关于通过代理服务器访问HTTPS站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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