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, 如和解决。获取到页面的值
服务器端做了跳转,所以,呵呵,不好办啊
xuexi
request.AllowAutoRedirect = true;
改成
request.AllowAutoRedirect = false;
试试