读书人

大家进来讨论上模拟post提交有关问题吧

发布时间: 2012-11-04 10:42:42 作者: rapoo

大家进来讨论下模拟post提交问题吧
比如我们自己做注册的网站,有号,密码,验证码
但是支持跨站提交。那么利用这点就可以让验证码只变一次。也就是说,只让他验证码刷新一次,存在session里
我手动可以实现输同一个验证码,一直注册
但是用webclient模拟post发送。
这时。怎么让session里面有东西?直接webclientdownstring("验证码网站");
再用updateloadbytes方法,提交验证码,是存在一个session里面的么?
我用的webRequest下载验证码图片,再用updateloadbytes提交,提示验证码错误,说明我下载的图片,和提交的图片,
不是在一个session里
有研究过的么。




可以跨站提交,手动能过他验证码,怎么用程序实现呢?
大家试试吧

[解决办法]
通常来说WebClient是不能保存session和cookie的
除非你重写一下。

post提交网页建议使用HttpWebRequest

附上一个简单的HttpRequest类

C# code
    public class HttpHelper    {        public static string contentType = "application/x-www-form-urlencoded";        public static string accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";        public static string userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Zune 4.7; BOIE9;ZHCN)";        public static string referer = "";        /// <summary>        /// 获取HTML        /// </summary>        /// <param name="url"></param>        /// <param name="cookieContainer"></param>        /// <param name="method">GET or POST</param>        /// <param name="postData">like "username=admin&password=123"</param>        /// <returns></returns>        public static string GetHtml(string url, CookieContainer cookieContainer = null, string method = "GET", string postData = "")        {            cookieContainer = cookieContainer ?? new CookieContainer();            HttpWebRequest httpWebRequest = null;            HttpWebResponse httpWebResponse = null;            try            {                httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);                httpWebRequest.CookieContainer = cookieContainer;                httpWebRequest.ContentType = contentType;                httpWebRequest.Referer = referer;                httpWebRequest.Accept = accept;                httpWebRequest.UserAgent = userAgent;                httpWebRequest.Method = method;                httpWebRequest.ServicePoint.ConnectionLimit = int.MaxValue;                if (method.ToUpper() == "POST")                {                    byte[] byteRequest = Encoding.Default.GetBytes(postData);                    Stream stream = httpWebRequest.GetRequestStream();                    stream.Write(byteRequest, 0, byteRequest.Length);                    stream.Close();                }                httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();                Stream responseStream = httpWebResponse.GetResponseStream();                StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);                string html = streamReader.ReadToEnd();                streamReader.Close();                responseStream.Close();                httpWebRequest.Abort();                httpWebResponse.Close();                return html;            }            catch (Exception)            {                return string.Empty;            }        }    } 

读书人网 >C#

热点推荐