gpt4 book ai didi

c# - 如何知道WebBrowser 导航是否出现错误页面?

转载 作者:行者123 更新时间:2023-11-30 13:05:58 24 4
gpt4 key购买 nike

例如,我们导航到http://www.ggg111.com ,这是一个错误的 URL。但在 WebBrowser 中它显示一个错误页面:

The webpage cannot be found  HTTP 400     Most likely causes:There might be a typing error in the address. If you clicked on a link, it may be out of date.    What you can try:      Retype the address.       Go back to the previous page.      Go to  and look for the information you want.  

如何知道浏览器浏览器是否浏览错误页面?

还要检查这个: https://sso.youshang.com/sso/userAuthnAction.do1

HTTP Status 404 - /sso/userAuthnAction.do1type Status reportmessage /sso/userAuthnAction.do1description The requested resource (/sso/userAuthnAction.do1) is not available.

最佳答案

基于此控件:http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx

有 NavigateError 函数,在导航过程中发生错误时触发。这是我修改后的代码:

首先添加事件参数类:


public class NavigateErrorArgs : EventArgs
{
public object StatusCode { get; set; }

public NavigateErrorArgs()
: base()
{ }

public NavigateErrorArgs(object statusCode)
: base()
{
this.StatusCode = statusCode;
}
}

然后在 ExtendedWebBrowser 类中添加委托(delegate)和事件:


public delegate void NavigateErrorHandler(object sender, NavigateErrorArgs e);
public event NavigateErrorHandler NavigateError;

protected void OnNavigateError(NavigateErrorArgs e)
{
if (NavigateError != null)
NavigateError(this, e);
}

and modify method in class WebBrowserExtendedEvents:


public void NavigateError(object pDisp, ref object URL, ref object frame, ref object statusCode, ref bool cancel)
{
_Browser.OnNavigateError(new NavigateErrorArgs(statusCode));
}

关于c# - 如何知道WebBrowser 导航是否出现错误页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/880811/

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