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

模拟post提交注册出现问题,验证码总说不正确,怎么办啊,真的是很急
我用下面代码下载到的验证码
HttpWebRequest h = (HttpWebRequest)HttpWebRequest.Create("http://9.52ms.org/vpn/include/vdimgck.php");

HttpWebResponse response = (HttpWebResponse)h.GetResponse();
pictureBox1.Image = new Bitmap(response.GetResponseStream());
CookieContainer cookie = new CookieContainer();
cookie.Add(response.Cookies);

用的下面这个方法调用模拟post提交
 string html = HttpHelper.GetHtml("http://9.52ms.org/vpn/useradmin/user_self_new_save.php", null, "POST", "ioBB=&regsdid=&chksdid=false&hidRecName001=&hidRecName002=&hidRecRule001=&hidRecRule002=&agent4IpCheck=checkIp&txtRegisterFrom=0&txtRegisterZone=0&sessionid=lr1c1w55vih4et45ct511krb&goldtype=&partner=&apptype=&agent=&ctype=&hidExinfo=&qqaccount=&CUSTOM_REG_EVN=&ptType=0&UserID=aab2" + i + "&Upassword=123123&Upassword2=123123&Email_Address=123@qq.com&User_True=&User_QQ=&idcard=&Description=&ThisNo="+textBox1.Text+"&btnSubmit=+%E7%AB%8B%E5%8D%B3%E6%B3%A8%E5%86%8C91vpn%E8%B4%A6%E5%8F%B7+");
MessageBox.Show(html);下面是post提交的方法。输入的验证码不一样,提示错误,请大家指示。为什么?难道这样模拟获取的验证码,没有效果么?
听说是什么cookies的问题?怎么整?
 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# 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-si