.NET 网络浏览器控件 - 自动进入弹出式登录表单 [英] .NET webbrowser control - Automate entry into pop up login form

查看:22
本文介绍了.NET 网络浏览器控件 - 自动进入弹出式登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望这不会太痛苦...

Hopefully this won't be too painful...

我正在尝试从 webbrowser 控件访问网站,我尝试了两种方法(实际上,更多来自谷歌搜索的混合结果)存在以下问题:

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:此方法导致弹出安全窗口,要求我登录公司代理.我猜这是因为我使用的是网站的用户名/密码,而 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:如果我直接访问网站而不编辑 URL:

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

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

然后它带我到了网站,根本没有任何代理消息(太棒了!)但是该网站会弹出一个我需要填充的登录框.遗憾的是,我无法为此(自动化)获取任何元素 ID,因为它是一个在 webbrowser 控件之外弹出的窗口窗体,我似乎无法询问它或弄清楚如何输入它.

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.

有人对我接下来应该尝试什么有任何想法吗?有什么方法可以让方法 2 中的登录表单自行填充或至少让我查看该页面的源代码?在正确填充之前,我无法点击它.

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.

我似乎无法让任何可以为我处理两个登录表单的工作,它要么是一个,要么是另一个.(这两种形式看起来都像 Windows 标准登录提示,它们没有内置到网页中).谢谢

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

推荐答案

您需要实现支持 IServiceProvider 的自定义浏览器控件站点并提供 IAuthenticate 作为服务.浏览器控件将在需要登录凭据时回调您的 IAuthenticate 实现.

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.

以下问答可能会帮助您入门,尽管代码是用 C# 编写的:

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

访问文件夹时网页浏览器控件身份验证不起作用 [保留原始拼写].

实现 IDispatch::Invoke 由 WebBrowser 调用控制.

更具体地说,您需要实施 IAuthenticateEx,这将允许您通过 AUTHENTICATEINFO.dwFlags.

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

这篇关于.NET 网络浏览器控件 - 自动进入弹出式登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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