.NET WebBrowser控件 - 自动进入弹出登录表单弹出、表单、控件、NET

2023-09-02 21:40:17 作者:回忆发狂 侵蚀了我眼眶ゅ

希望这不会太痛......

我想从一个WebBrowser控件访问一个网站,我已经尝试了两种方法(实际上好了,其它更多的结果好坏参半使用Google)具有以下问题:

  URL =HTTP://用户名:password@thewebsite.com
 WebBrowser1.Navigate时(URL)
 

1:此方法将导致在一个窗口中的安全弹出,问我登录到公司的代理。我想这是因为我使用的用户名/密码的网站和网址导航正在试图将其输入到代理?

如果我试图自动/避免代理位这样做的:

 昏暗的标题为String =代理授权:基本和放大器; Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(用户名:密码))
WebBrowser1.Navigate时(网址,Encoding.Uni code.GetBytes(的String.Empty),标题)
 
jQuery弹出层登录页面表单

我仍然未能满足作为代理登录框弹出不管。

2: 如果我直接去该网站没有编辑的网址:

  URL =htt​​p://thewebsite.com
 WebBrowser1.Navigate时(URL)
 

然后带我到德网站没有任何代理的消息在所有(太棒了!),但是该网站,然后在框中,我需要填充弹出一个日志。可悲的是,我不能抓住任何elementids这个(自动),因为它是一个Windows窗体弹出WebBrowser控件之外,我似乎无法询问,或找出如何输入进去。

有没有人有任何想法,我应该尝试下?是否有某种方式来获得方法2要么填充自身,或者至少让我查看该页面的源代码的登录表单?我无法点击远离它,直到它无误。

我只是似乎无法得到任何工作,将与两个日志经营形式对我来说,它可以是一个或另一个。 (这两种形式看起来像Windows标准的日志中提示,他们是没有内置网页)。 谢谢

解决方案

您就需要实现自定义浏览器控件的网站支持的IServiceProvider 提供的 IAuthenticate进行的服务。浏览器控件将回拨你的 IAuthenticate进行的实施时,它需要的登录凭据。

以下Q / A可以帮助你上手,虽然code是在C#:

WEbbrowser控制autheticate不工作时访问文件夹 [原创拼写preserved。

Implement的IDispatch ::调用由WebBrowser控件被调用。

更具体地说,你需要实现的 IAuthenticateEx ,这样可以让你通过的 AUTHENTICATEINFO.dwFlags 。

Hopefully this won't be too painful...

I am trying to access a website from a webbrowser control, I have tried two methods (well actually, lots more from googling with mixed results) that have the following problems:

 URL = "http://username:password@thewebsite.com"
 WebBrowser1.Navigate(URL)

1: This method results in a window security pop up, asking me to log in to the company proxy. I guess this is because I am using the username/password for the website and the URL navigation is attempting to input it to the proxy?

If I attempt to automate/avoid the proxy bit by doing this:

Dim Headers As String = "Proxy-Authorization: Basic " & Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("USERNAME:PASSWORD"))
WebBrowser1.Navigate(URL, "", Encoding.Unicode.GetBytes(String.Empty), Headers)

I still meet with failure as the proxy log in box pops up regardless.

2: If I go straight to the website without editing the URL:

 URL = "http://thewebsite.com"
 WebBrowser1.Navigate(URL)

Then it takes me to teh website without any proxy messages at all (great!) but the website then pops up a log in box that I need to populate. Sadly I cannot get hold of any elementids for this (to automate) as it is a windows form pop up outside of the webbrowser control, and I cannot seem to interrogate it or figure out how to input into it.

Does anyone have any ideas for what I should try next? Is there some way to get the login form from method 2 to either populate itself or at least let me view the source of that page? I cannot click away from it until it is populated correctly.

I just cannot seem to get anything to work that will deal with both log in forms for me, it is either one or the other. (both forms look like windows standard log in prompts, they are not built into the webpage). Thanks

解决方案

You'd need to implement a custom browser control site supporting IServiceProvider and provide IAuthenticate as service. The browser control will call back your IAuthenticate implementation whenever it needs login credentials.

The following q/a might help you to get started, although the code is in C#:

WEbbrowser control autheticate not working when access file folder [original spelling preserved].

Implement IDispatch::Invoke to be called by a WebBrowser control.

[EDITED] More specifically, you'd need to implement IAuthenticateEx, which would allow you to differentiate between proxy and website authentication via AUTHENTICATEINFO.dwFlags.