简体   繁体   English

在c#的“ System.Net.NetworkCredential”中使用未过载的webclient输入网页身份验证

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

I'm trying to connect and download website content that requires an authentication that is not "overloaded". 我正在尝试连接和下载需要不“超载”身份验证的网站内容。

The options are: 选项包括:

  • user 用户
  • user+password, 用户密码
  • user+password+domain 用户+密码+域名

I need user+subscriber+password. 我需要用户+用户+密码。 How can i pass this credentials? 我如何通过此凭证?

code: 码:

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/");
...  
}

How i solved the problem: used a POST method with improvedWebClient class, that is like webclient but one that saves cookies. 我如何解决该问题:使用了带有经过改进的WebClient类的POST方法,就像webclient一样,但是它保存了cookie。 you can find it here . 你可以在这里找到它。
code: 码:

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);

thanks for the help guys. 谢谢你们的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM