日期:2014-05-17  浏览次数:20889 次

用winform做的HttpWebRequest 模拟登陆器,post参数要如何暗文发送?
用了Encrypt()不是会改变原值吗?发送的账号密码就会提示不正确,怎么加密呢?




            Uri uri = new Uri(web_url);
            NameValueCollection values = new NameValueCollection();
            values.Add("username", this.Encrypt(username, key));
            values.Add("password", this.Encrypt(password, key));
            string data = this.PostData(uri, values, true);



private string PostData(Uri uri, NameValueCollection values, [Optional, DefaultParameterValue(true)] bool status)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.Accept = "*/*";
                request.Headers.Add("Accept-Encoding: gzip,deflate");
                request.Headers.Add("Accept-Language: zh-cn");
                request.ServicePoint.Expect100Continue = false;
                request.KeepAlive = true;
                request.UserAgent = "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25";
                if (status)
                {
                    CookieContainer container = new CookieContainer();
                    container.Add(uri, new Cookie("cookie", this.SessionID));
                    //container.Add(uri, new Cookie("Version", this.Version));
                    request.CookieContainer = container;
                }
    &nb