繁体   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