422进行HTTP请求身份验证后无法处理的实体

时间:2019-07-24 13:45:52

标签: c# html

我正在尝试运行scrapingWeb应用程序,以获取需要身份验证的HTML网站的内容。我尝试了没有任何锁定的代码段,每次都遇到422错误:无法处理的实体。

public class CookieAwareWebClient : WebClient
{
    private CookieContainer cookie = new CookieContainer();

    protected override WebRequest GetWebRequest(Uri address)
    {
        WebRequest request = base.GetWebRequest(address);
        if (request is HttpWebRequest)
        {
            (request as HttpWebRequest).CookieContainer = cookie;
        }
        return request;
    }
}
  static public void GetAttachment()
    {
   var client = new CookieAwareWebClient();
  client.BaseAddress = @"https://www.s2-digit-farm.info/redmine/login.html";
  var loginData = new NameValueCollection();
  loginData.Add("username", "user");
  loginData.Add("password", "pass");
  client.UploadValues("login.html", "POST", loginData);
  Console.WriteLine("loged");
 }

有人有什么主意吗? 谢谢

0 个答案:

没有答案