Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何在mvc中使用webclient登录网站_Asp.net_Asp.net Mvc 4 - Fatal编程技术网

Asp.net 如何在mvc中使用webclient登录网站

Asp.net 如何在mvc中使用webclient登录网站,asp.net,asp.net-mvc-4,Asp.net,Asp.net Mvc 4,我在如何使用webclient登录网站方面遇到问题。我正在从代码端发送凭据,没有收到任何响应。查看此链接查看此链接 public string checkAuthentication() { using (var client = new CookieAwareWebClient()) { string cookie = string.Empty; var values = new NameValueCollection

我在如何使用webclient登录网站方面遇到问题。我正在从代码端发送凭据,没有收到任何响应。

查看此链接查看此链接
public string checkAuthentication()
{
    using (var client = new CookieAwareWebClient())
    {
        string cookie = string.Empty;
        var values = new NameValueCollection
                    {
                        { "ctl00$cphContent$txtUserName", "username" },
                        { "ctl00$cphContent$txtPWD", "pwd" },
                    };
        client.UploadValues(new Uri(Url), "POST", values);

        // If the previous call succeeded we now have a valid authentication cookie
        // so we could download the protected page


        cookie = client.ResponseHeaders["Set-Cookie"].ToString();
        string a = ".ASPXAUTH=F4E1FAFB36A0AC53C6F406ACA8F618EEF5128B1DF864B806F64E7983ED6279FB821FFB3A06553D03B8CA00BC5E4DA8F211E2192A986201AC63220B10E2C4B5174BD28A81171231A9E3636E79897A2F4F52404E9B6560698F9B9108ACD5A60A9E6E0188EE697882685A0D9602ACD2E1AA639522DFC4B0C6CF8FA5DD9DE7C559158D474157C73152916753935582098AF78A7F547FD4DADC6260C882674767F987436015538571310C3871ACFA432C96722C5DBF1BDEF911C2EDE6DFA35B15A46F08B5BBAF78A14BD16EE47438E13A29BB33F1694575C3F3B370C9D1A3F96665D4F8D3CDC92CFFDC0141E9C127C487435E;  path=/; HttpOnly,ASP.NET_SessionId=55eslczotoisz0oh32ldu5gq; path=/; secure; HttpOnly";
        client.Headers.Add("Cookie", a);
        string result = client.DownloadString(new Uri(Url));
        return result;
    }
}