本文介绍了HTTP POST返回错误:417"期望失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码返回错误:417期望失败.为什么?谢谢!
this code Returns The Error: 417 "Expectation Failed.why?thank!!!
CookieContainer cookie=new CookieContainer();
Encoding encoding=Encoding.GetEncoding("gb2312");
void Button1Click(object sender, EventArgs e)
{
HttpWebRequest req=WebRequest.Create("http://reg.email.163.com/mailregAll/reg0.jsp?from=163mail_right") as HttpWebRequest;
req.Method="GET";
req.Accept="*/*";
req.Referer="http://mail.163.com/";
req.UserAgent="Mozilla/4.0";
req.CookieContainer=cookie;
req.KeepAlive=true;
HttpWebResponse resp=req.GetResponse() as HttpWebResponse;
Stream respStream=resp.GetResponseStream();
StreamReader respReader=new StreamReader(respStream,encoding);
string page=respReader.ReadToEnd();
respStream.Close();
respReader.Close();
string imageUrl="http://reg.email.163.com/mailregAll/regv2/verifyCodeImg.jsp?t=";
TimeSpan span=DateTime.Now-Convert.ToDateTime("1970-01-01");
double tt=((span.TotalMilliseconds)/1000)-(8*3600);
string time=tt.ToString();
imageUrl+=time;
req=WebRequest.Create(imageUrl) as HttpWebRequest;
req.Method="GET";
req.Accept="*/*";
req.Referer="http://mail.163.com/";
req.UserAgent="Mozilla/4.0";
req.CookieContainer=cookie;
req.KeepAlive=true;
resp.Cookies=cookie.GetCookies(req.RequestUri);
resp=req.GetResponse() as HttpWebResponse;
respStream=resp.GetResponseStream();
Image image=new Bitmap(respStream);
pictureBox1.Image=image;
respStream.Close();
}
void Button2Click(object sender, EventArgs e)
{
HttpWebRequest req=WebRequest.Create("http://reg.email.163.com/mailregAll/createmail2.do") as HttpWebRequest;
req.Method="POST";
// req.Accept="application/json, text/javascript, */*";
req.Referer="http://reg.email.163.com/mailregAll/reg0.jsp?from=163mail_right";
req.UserAgent="Mozilla/4.0";
req.ContentType="application/x-www-form-urlencoded";
req.CookieContainer=cookie;
req.KeepAlive=true;
string postString="uname=ioriliaotest3&" +
"password=19850420&" +
"passwordconf=19850420" +
"&mobile=&verifycode="+
HttpUtility.UrlEncode(textBox1.Text,encoding)+
"&dmain=163.com&version=regvf1";
byte[] postByte=Encoding.ASCII.GetBytes(postString);
Stream reqStream=req.GetRequestStream();
reqStream.Write(postByte,0,postByte.Length);
reqStream.Close();
//error in this
HttpWebResponse resp=req.GetResponse() as HttpWebResponse;
Stream respStream=resp.GetResponseStream();
StreamReader respReader=new StreamReader(respStream,encoding);
richTextBox1.AppendText(respReader.ReadToEnd());
respStream.Close();
respReader.Close();
}
推荐答案
System.Net.ServicePointManager.Expect100Continue = false;
这篇关于HTTP POST返回错误:417"期望失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!