gpt4 book ai didi

c# - 如何强制 Web 浏览器控件记住代理凭据设置?

转载 作者:太空宇宙 更新时间:2023-11-03 13:57:19 25 4
gpt4 key购买 nike

我正在使用 .net Web 浏览器控件通过具有凭据的代理在新窗口中打开 url。我为此使用了这段代码:

Public Function AppendHeader(ByRef OriginalHeader As String, ByVal Addition As String) As Boolean
If OriginalHeader <> "" Then
OriginalHeader = OriginalHeader + vbNewLine
End If
OriginalHeader = OriginalHeader + Addition
OriginalHeader.Trim(vbNewLine.ToCharArray)
End Function

Public Function Base64Enc(ByRef s As String) As String
Base64Enc = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(s))
End Function

Public Sub Navigate()
Dim webBrowser As WebBrowser = New WebBrowser()
Dim headers As String = ""
AppendHeader(headers, "Proxy-Authorization: Basic " & Base64Enc("user:pass"))
'AppendHeader(headers, "Authorization: Basic " & Base64Enc("user:pass"))
webBrowser.Navigate("http://stackoverflow.com", Guid.NewGuid().ToString(), Nothing, headers)
End Sub

此代码有助于在第一时间隐藏 Windows 安全窗口,但如果加载网页向其他 url 发送请求,此窗口会一次又一次地显示(您可以在下面的屏幕截图中看到)。

screenshot

那么我该怎么做才能解决这个问题呢?(我用的是winforms和vb.net,不过C#也适合)

最佳答案

试一试我无法测试它:)

Private Sub webBrowser_Navigating(ByVal sender As Object, ByVal e As WebBrowserNavigatingEventArgs)

Dim credentials As New System.Net.NetworkCredential("user", "pwd", "MyDomain")
Dim proxy As New System.Net.WebProxy("127.0.1.2", 80)
If proxy Is Nothing Then
e.Cancel = True
End If

End Sub

关于c# - 如何强制 Web 浏览器控件记住代理凭据设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11756456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com