62,046
社区成员
发帖
与我相关
我的任务
分享
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
}