|
6 | 6 | ''' </summary> |
7 | 7 | ''' <returns>返回 WebProxy 或者 Nothing</returns> |
8 | 8 | Public Function GetProxy() |
9 | | - Dim proxy As String = Setup.Get("SystemHttpProxy") |
10 | | - Dim SystemProxy As New WebProxy(WebRequest.GetSystemWebProxy().GetProxy(New Uri("https://www.example.com"))) |
11 | | - If SystemProxy IsNot Nothing AndAlso Setup.Get("SystemUseDefaultProxy") Then |
12 | | - Log("[Net] 当前代理状态:跟随系统代理设置") |
13 | | - Return SystemProxy |
| 9 | + Dim ProxyServer As String = Setup.Get("SystemHttpProxy") |
| 10 | + Dim SystemProxyServer As String = WebRequest.GetSystemWebProxy().GetProxy(New Uri("https://www.example.com/")).ToString |
| 11 | + If SystemProxyServer.Equals("https://www.example.com/") Then '没有系统代理的情况下会返回原始 Uri,这导致了使用此方法获取系统代理的网络请求全部炸掉 |
| 12 | + Log("[Net] 检测到未设置系统代理,已忽略系统代理") |
| 13 | + ElseIf Not SystemProxyServer.StartsWithF("http:") Then |
| 14 | + Log("[Net] 检测到不支持的代理服务器协议,已忽略系统代理") |
| 15 | + Else |
| 16 | + Dim SystemProxy As New WebProxy(New Uri(SystemProxyServer)) |
| 17 | + If SystemProxy IsNot Nothing AndAlso Setup.Get("SystemUseDefaultProxy") Then |
| 18 | + Log("[Net] 当前代理状态:跟随系统代理设置") |
| 19 | + Return SystemProxy |
| 20 | + End If |
14 | 21 | End If |
15 | | - If Not String.IsNullOrWhiteSpace(proxy) AndAlso Not Setup.Get("SystemUseDefaultProxy") Then |
| 22 | + If Not String.IsNullOrWhiteSpace(ProxyServer) Then |
16 | 23 | Log("[Net] 当前代理状态:自定义") |
17 | | - Dim ProxyUri As New Uri(proxy) |
| 24 | + Dim ProxyUri As New Uri(ProxyServer) |
18 | 25 | Try |
| 26 | + If Not ProxyUri.Scheme.ContainsF("http:") Then Return Nothing |
19 | 27 | If ProxyUri.IsLoopback OrElse |
20 | 28 | ProxyUri.Host.StartsWithF("192.168.") OrElse |
21 | 29 | ProxyUri.Host.StartsWithF("10.") OrElse |
|
24 | 32 | '视作非本地地址 |
25 | 33 | Catch |
26 | 34 | End Try |
27 | | - Return New WebProxy(proxy, True) |
| 35 | + Return New WebProxy(ProxyServer, True) |
28 | 36 | End If |
29 | 37 | Log("[Net] 当前代理状态:禁用") |
30 | 38 | Return Nothing |
|
0 commit comments