如何使用Webclient登录Amway.com

时间:2014-05-17 07:39:22

标签: c# html post webclient

任何人都可以使用代码向我解释如何使用WEbClient登录Amway.com。现在我想出了这个问题。请提供建议或链接到我可以学习和完成的其他材料。提前谢谢。

using (var client = new CookieAwareWebClient())
            {
                System.Net.ServicePointManager.Expect100Continue = false;
                WebHeaderCollection headers = new WebHeaderCollection();
                headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
                headers.Add("Accept-Encoding", "gzip, deflate");
                headers.Add("Accept-Language", "en-US,en;q=0.5");
                headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.2; rv:30.0) Gecko/20100101 Firefox/30.0");
                client.Headers = headers;
                var values = new NameValueCollection
                {
                    { "ctl00$ContentPlaceHolder1$LoginControl$UserName", "username" },
                    { "ctl00$ContentPlaceHolder1$LoginControl$Password", "password" },
                };
                byte[] result = client.UploadValues("https://www.amway.in/Users/Login.aspx", "POST", values);
                string response = Encoding.ASCII.GetString(result);
            }


public class CookieAwareWebClient : WebClient
    {
        public CookieAwareWebClient()
        {
            CookieContainer = new CookieContainer();
        }
        public CookieContainer CookieContainer { get; private set; }

        protected override WebRequest GetWebRequest(Uri address)
        {
            var request = (HttpWebRequest)base.GetWebRequest(address);
            request.CookieContainer = CookieContainer;
            return request;
        }
    }

0 个答案:

没有答案