HTTP POST返回错误:417"期望失败 [英] HTTP POST Returns The Error: 417 "Expectation Failed

查看:94
本文介绍了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();
		}

推荐答案

^ ]

还是 google [
http://social.msdn.microsoft.com/Forums/en-US/devdocs/thread/60cd6e6a-4157-4811-8ed3-1e46f9022ea8/[^]

Or google[^].


此错误很少发生在大多数Web流量中,尤其是当客户端系统是Web浏览器.这种类型的Web流量很少使用期望"请求.

如果您的客户端系统不是Web浏览器,则只能通过检查客户端正在尝试执行的操作然后与ISP讨论为什么Web服务器未能通过客户端系统发送的期望"请求来解决该问题.
This error seldom occurs in most Web traffic, particularly when the client system is a Web browser. This type of Web traffic seldom uses an "Expect" request.

If your client system is not a Web browser, the problem can only be resolved by examining what the client is trying to do then discussing with your ISP why the Web server fails the "Expect" request sent by the client system.


Google是您的朋友(搜索短语="4167期望失败":

第一个链接:

http://www.checkupdown.com/status/E417.html [
Google is your friend (search phrase = "4167 expectation failed":

First link:

http://www.checkupdown.com/status/E417.html[^]

2nd link provided this:

System.Net.ServicePointManager.Expect100Continue = false; 


这篇关于HTTP POST返回错误:417"期望失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆