Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用默认浏览器打开具有基本授权的url?_C#_Url_Authentication - Fatal编程技术网

C# 如何使用默认浏览器打开具有基本授权的url?

C# 如何使用默认浏览器打开具有基本授权的url?,c#,url,authentication,C#,Url,Authentication,我需要使用用户凭据在C#程序中打开URL。我试着像这样使用WinformWebBrowser: string user = "user"; string pass = "pass"; string authHdr = "Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + pass)) + "\r\n"; webBrowser1.Navigate("http://example.c

我需要使用用户凭据在C#程序中打开URL。我试着像这样使用Winform
WebBrowser

string user = "user";
string pass = "pass";
string authHdr = "Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + pass)) + "\r\n";
webBrowser1.Navigate("http://example.com/userProfile", null, null, authHdr);
而且效果很好。然而,WinFormWebBrowser窗口不像IE、Fireworks、Chrome等浏览器那样友好

所以我想知道是否有任何方法可以在默认浏览器中以基本授权打开URL。寻找任何想法。谢谢

using (System.Diagnostics.Process process = new System.Diagnostics.Process())
{
    try
    {
        process.StartInfo.FileName = "explorer.exe";
        process.StartInfo.Arguments = "http://stackoverflow.com/";
        process.Start();
    }
    catch (System.Exception e)
    {
    }
}

你是这个意思吗?

我回答了一个类似的问题

概述: Net中的WebBrowser控件使用Internet Explorer作为浏览器,因此如果您不介意使用IE,这就是我编写的代码h5url是要在窗口中打开的url。我的程序甚至没有显示浏览器控件,这是生成一个Internet Explorer实例,该实例的网页已登录,凭据信息编码在标题中。(用户/密码变量)


这将打开一个新浏览器,其中包含身份验证所需的任何标题(基本或其他)。

谢谢您的回答!实际上,我试图做的是在使用IE等浏览器打开网站时传递凭据信息。这可以通过使用WebBrowser来完成。但是,它对用户不友好。我搜索了很长时间,找到的唯一可能的解决方案如下:
http(s)://用户名:password@example.com/userProfile
但它会公开凭据。。。。
     using (WebBrowser WebBrowser1 = new WebBrowser())
            {
                String auth =
                    System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(_User + ":" + _Password));
                string headers = "Authorization: Basic " + auth + "\r\n";
                WebBrowser1.Navigate(h5URL, "_blank", null, headers);

            }