当前位置:编程学习 > C#/ASP.NET >>

httpwebrequest重定向问题

最近用.NET做一个winform小程序直接向某一个网站POST数据,但是此网站含有302重定向的操作。导致我每次POST数据过去都返回“服务器繁忙”的信息,请问这块该怎么做啊。。
第一步我登录已经成功了。第二步向POST数据的时候服务器返回“服务器繁忙”,抓包如下:
__EVENTTARGET=cb&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwUKMTc5MjQ1NDQ4N2QYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFAmNi&cb=on&__EVENTVALIDATION=%2FwEWAgKb2NMIAr3vou8M
以上是POST的数据(为固定的,不会变)


以下是我源代码:
string xxoo = http.GetHtml("http://www.scjj.gov.cn:8635/zzyy.aspx", "__EVENTTARGET=cb&__EVENTARGUMENT=&__LASTFOCUS=&_VIEWSTATE=%2FwEPDwUKMTc5MjQ1NDQ4N2QYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFAmNi&cb=on&__EVENTVALIDATION=%2FwEWAgKb2NMIAr3vou8M",Method.POST, http.Cookievalue, "http://www.scjj.gov.cn:8635/zb_ksyy.aspx");

 public string GetHtml(string url, string postData, Method method, string cookie, string referer)
        {
            byte[] byteRequest = Encoding.UTF8.GetBytes(postData);

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(url));
            req.Proxy = null;
            req.ContentType = this.contentType;
            req.Referer = referer;
            req.UserAgent = this.userAgent;
            req.Accept = this.accept;
            req.ContentLength = byteRequest.Length;
            req.Method = method == Method.POST ? "POST" : "GET";
            req.Headers.Add("Cookie", cookie);         
            //将需要post的数据写入请求流
            Stream streamReq = req.GetRequestStream();
            streamReq.Write(byteRequest, 0, byteRequest.Length);
            streamReq.Close();
            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            Stream stream = res.GetResponseStream();
            StreamReader reader = new StreamReader(stream, Encoding.UTF8);
            string result = reader.ReadToEnd();
            reader.Close();
            stream.Close();
            //cookieCollection = cc.GetCookies(new Uri(url));
            return result;
        }

从上图可以看出,先向zzyy.aspx POST数据之后,马上有个重定向到zb_ksyy.aspx这个页面了。。我如何才能取到zb_ksyy.aspx页面中的响应数据;
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,