How can i open a url in web browser (such as IE) and pass credentials

前端 未结 5 1066
傲寒
傲寒 2020-12-09 10:15

I want to open a page that required Basic authentication. I want to pass the Basic authentication header to the browser along with the URL.

How can i do that?

5条回答
  •  情歌与酒
    2020-12-09 11:14

    Via a header you can:

    string user = "uuuuuuu";
    string pass = "ppppppp";
    string authHdr = "Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + pass)) + "\r\n";
    
    webBrowserCtl.Navigate("http://example.com", null, null, authHdr);
    

    given that this needs to be done on a per-request basis, an easier option for basic auth is to just;

    webBrowserCtl.Navigate("http://uuuuuuu:ppppppp@example.com", null, null, authHdr);
    

提交回复
热议问题