[紧张求助]程序化上传文件时:417 Expectation Failed

sxlfybb 2008-07-11 04:43:17
我给客户程序上传文件到youtube.但在上传文件最后一步,报错:417 Expectation Failed
折腾了三四天了,就这一个小问题,还是没解决掉。今天最后一天了,望大家帮我看看是什么问题。
以下是上传的源代码:

void StartUpload(CookieContainer cookie)
{//cookie是以前已经获取到的登录cookie
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("field_command", "myvideo_submit");
dic.Add("field_myvideo_keywords", info.Video.Tags);
dic.Add("field_myvideo_title", info.Video.Title);
dic.Add("field_myvideo_descr", info.Video.Description);
dic.Add("field_myvideo_categories", info.Video.CateValue);
dic.Add("language", "EN");
dic.Add("field_privacy", "public");
dic.Add("field_private_share_entities", "");
dic.Add("addresser", urlenc);
dic.Add("contact", "");
dic.Add("field_date_day", "0");
dic.Add("field_date_yr", "0");
dic.Add("field_date_mon", "0");
dic.Add("location", "");
dic.Add("allow_comments", "Yes");
dic.Add("allow_comment_ratings", "Yes");
dic.Add("allow_responses", "Yes");
dic.Add("allow_embedding", "Yes");
dic.Add("allow_offweb", "Yes");
dic.Add("allow_ratings", "Yes");
dic.Add("allow_syndication", "Yes");
//dic.Add("session_token", "n3jq1-akmi0yw725MxxR3vzbroR8MTIxNTg1MDA4NQ==");
//dic.Add("field_uploadfile", string.Format("&field_uploadfile=filename=\"{0}\" Content-Type: text/plain", info.Video.Location));

ArrayList bytesArray = new ArrayList();

foreach (KeyValuePair<string, string> pair in dic)
{//CreateFieldData是拿的宝玉的组装post数据的方法,可以在http://blog.joycode.com/dotey/archive/2005/04/17/49153.aspx里看到
bytesArray.Add(CreateFieldData(pair.Key, pair.Value));
}
byte[] postArray = File.ReadAllBytes(info.Video.Location);
bytesArray.Add(CreateFieldData("field_uploadfile", new FileInfo(info.Video.Location).Name, "text/plain", postArray));
byte[] data = JoinBytes(bytesArray);
string url = urladd;
HttpWebRequest web = (HttpWebRequest)WebRequest.Create(url);
if (ConnectionType == NetType.TOR)
web.Proxy = new WebProxy("127.0.0.1", 8118);
else if (ConnectionType == NetType.Proxy && this.Proxy != null)
web.Proxy = this.Proxy;
web.CookieContainer = cookie;
web.Method = "POST";
web.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0";
web.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
web.Referer = "http://www.youtube.com/my_videos_upload";
web.KeepAlive = true;
web.ContentType = ContentType;

//uploadFile(info.Video.Location, url, cookie,data);
Stream sem;
web.ContentLength = data.Length;
sem = web.GetRequestStream();

if (sem.CanWrite)
sem.Write(data, 0, data.Length);
sem.Close();

HttpWebResponse res = (HttpWebResponse)web.GetResponse();//在这里报的错,
cookie.Add(res.Cookies);
Stream stream = res.GetResponseStream();
string WebContent = new StreamReader(stream, System.Text.Encoding.Default).ReadToEnd();

this.info.Finish(info);
System.Threading.Thread.CurrentThread.Abort();
// MessageBox.Show(WebContent);
//Redirect to: http://www.youtube.com/my_videos_upload_complete?claim_video=&has_in_video_ads=&rev_share=0&video_id=NHOfkJxVzp4&rev_share_description=&has_afv_overlay=&action_from_upload=1
}



分数不是问题,只要解决了,绝对加分。
...全文
495 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
linjian19811027 2010-05-04
  • 打赏
  • 举报
回复
System.Net.ServicePointManager.Expect100Continue = false;
sxlfybb 2008-07-11
  • 打赏
  • 举报
回复
兄弟们,救命呀~,时间宝贵呀,
sxlfybb 2008-07-11
  • 打赏
  • 举报
回复
7楼兄弟,你提供的页面,我已经看过了,没有什么帮助呀。
glboy12 2008-07-11
  • 打赏
  • 举报
回复
http://my.donews.com/buffalo319/category/http%E5%8D%8F%E8%AE%AE/
去这里看一下,另外看一下有没有权限?
sxlfybb 2008-07-11
  • 打赏
  • 举报
回复
但我按照httpfox捕捉到的header以及post参数全部上传了。汗,还这样。
3楼的大大,提供的页面,打不开

Sorry, we were unable to service your request. Please try again later.

For the latest headlines and to see what’s new, visit the MSDN home page.
sxlfybb 2008-07-11
  • 打赏
  • 举报
回复
我看到说明:

期望失败 417 Expectation Failed

Expect请求报头域给出的期望不能被服务满足,或者服务有确凿的证据表明请求不能被下一个服务满足
sxlfybb 2008-07-11
  • 打赏
  • 举报
回复
我晕,看到有回复,马上看,结果。。。

不过还是要感谢你。
greystar 2008-07-11
  • 打赏
  • 举报
回复
http://forums.msdn.microsoft.com/zh-CN/devdocs/thread/60cd6e6a-4157-4811-8ed3-1e46f9022ea8/
Ny-6000 2008-07-11
  • 打赏
  • 举报
回复
帮顶个

我也不会。
而且我遇过个问题,三四周了也没解决…………

郁闷啊。
sxlfybb 2008-07-11
  • 打赏
  • 举报
回复
马上就要下班了,希望各位大大在下班前,帮我看看。。。我实在受不了了,三四天解决不了这一个问题。不想活了。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧