簡體   English   中英

在c#的“ System.Net.NetworkCredential”中使用未過載的webclient輸入網頁身份驗證

[英]enter webpage authentication with webclient that's not overloaded in “System.Net.NetworkCredential” in c#

我正在嘗試連接和下載需要不“超載”身份驗證的網站內容。

選項包括:

  • 用戶
  • 用戶密碼
  • 用戶+密碼+域名

我需要用戶+用戶+密碼。 我如何通過此憑證?

碼:

WebClient client = new WebClient();  
public void search()  
{  
        client.Credentials = new System.Net.NetworkCredential(username, subscriber, password); //not really exist  
        Byte[] pageData = client.DownloadData("https://example.com/");
...  
}

我如何解決該問題:使用了帶有經過改進的WebClient類的POST方法,就像webclient一樣,但是它保存了cookie。 你可以在這里找到它。
碼:

ImprovedWebClient wc = new ImprovedWebClient();
wc.DownloadData("https://theWebSite.com"); //to enter home page and get cookie
string URI = "https://theWebSite.com/authenticate"; //the login page
string myParameters = "user=theUserName&subscriber_number=1234-5678&password=myPassword&commit=LogIn"; //the parameters for the website
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.UploadString(URI, myParameters);

謝謝你們的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM