问题解决了,利用Fiddler2获取cookie,然后找出变化的数据,带着变化的数据去访问,怎么感觉说不清楚呢,直接上代码
程序代码:
public static void SendInfo(string postData, string infoUrl, CookieContainer myCookieContainer)
{
byte[] byteArray = Encoding.GetEncoding("GBK").GetBytes(postData);
try
{
//发出对url的请求
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(infoUrl);
httpWebRequest.Timeout = 3000000;
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.15 Safari/536.5";
httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
//得到cookie
// httpWebRequest.CookieContainer = myCookieContainer;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
//协议方式
httpWebRequest.Method = "POST";
//与internet建立持久连接
httpWebRequest.KeepAlive = true;
//post开始
//请求内容长度
httpWebRequest.ContentLength = byteArray.Length;
Stream dataStream = httpWebRequest.GetRequestStream();
// 请求数据放入请求流
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
//返回html
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
if (httpWebResponse.StatusCode == HttpStatusCode.OK)
{
string gid = "";
StreamReader reader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.GetEncoding("GBK"));
//读取响应流
string responseFromServer = reader.ReadToEnd();//这里是获得的html
reader.Close();
dataStream.Close();
httpWebResponse.Close();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}