首页 新闻 搜索 专区 学院

post 302

0
悬赏园豆:30 [已关闭问题]

 public string GetPage(string url, string postData, string encodeType, out string err)
       {
           Stream outstream = null;
           Stream instream = null;
           StreamReader sr = null;
           HttpWebResponse response = null;
           HttpWebRequest request = null;

           Encoding encoding = Encoding.GetEncoding(encodeType);
           byte[] data = encoding.GetBytes(postData);

           // 准备请求...
           try
           {
               // 设置参数
               request = WebRequest.Create(url) as HttpWebRequest;
               CookieContainer cookieContainer = new CookieContainer();
               request.CookieContainer = cookie;
               request.AllowAutoRedirect = true;
               request.Method = "POST";
               request.ContentType = "application/x-www-form-urlencoded";
               request.ContentLength = data.Length;
               outstream = request.GetRequestStream();
               outstream.Write(data, 0, data.Length);
               outstream.Close();
               //发送请求并获取相应回应数据
               response = request.GetResponse() as HttpWebResponse;
               //response.Headers.Add("Location", "http://www.jjoobb.cn/Error.htm?aspxerrorpath=/Resume/ApplyResume.aspx");
               //这里也拿不到
               //string newUrl = response.Headers["Location"].ToString();

               //直到request.GetResponse()程序才开始向目标网页发送Post请求
               instream = response.GetResponseStream();
               sr = new StreamReader(instream, encoding);

               //返回结果网页(html)代码
               string content = sr.ReadToEnd();
               err = string.Empty;

               return content;
           }
           catch (Exception ex)
           {
               err = ex.Message;
               return string.Empty;
           }

       }

 

 

是用这个方法  post 一个网页 。

返回302,  如和解决。获取到页面的值

夏雷的主页 夏雷 | 初学一级 | 园豆:165
提问于:2008-11-24 12:58
< >
分享
其他回答(2)
0

服务器端做了跳转,所以,呵呵,不好办啊

丁学 | 园豆:18530 (专家六级) | 2008-11-24 13:36
0

xuexi

Jared.Nie | 园豆:1940 (小虾三级) | 2008-11-24 14:15
0

request.AllowAutoRedirect = true;

改成

request.AllowAutoRedirect = false;

试试

代码示例 | 园豆:49 (初学一级) | 2008-12-05 18:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册