public Response <XParseDocument> Upload(WebFormDownloadSettings settings) { AsyncArgs args = new AsyncArgs(null) { Settings = settings }; if (settings.Account.Crumb == string.Empty) { Html2XmlDownload html = new Html2XmlDownload(); html.Settings.Account = settings.Account; html.Settings.Url = settings.Url; Response <XParseDocument> resp = html.Download(); this.ConvertHtml(resp.Result, args); } PostDataUpload dl = new PostDataUpload(); this.PrepareDownloader(dl, args); if (dl.Settings.PostStringData != string.Empty) { DefaultResponse <System.IO.Stream> resp = (DefaultResponse <System.IO.Stream>)dl.Download(); return(resp.CreateNew(MyHelper.ParseXmlDocument(resp.Result))); } else { return(null); } }
private void PrepareDownloader(PostDataUpload dl, AsyncArgs args) { if (args.Settings.Account.Crumb != string.Empty || args.IsLoginChallenge) { if (args.Settings.DownloadResponse) { dl.Settings.DownloadResponse = true; } bool setCrumb = true; if (args.Settings.AdditionalWebForms.Count > 0 && !args.IsLoginChallenge) { for (int i = 0; i < args.Settings.AdditionalWebForms.Count; i++) { if (args.Settings.AdditionalWebForms[i].Key == ".yficrumb") { args.Settings.AdditionalWebForms[i] = new KeyValuePair <string, string>(".yficrumb", args.Settings.Account.Crumb); setCrumb = false; break; } } } if (args.IsLoginChallenge) { setCrumb = false; } if (setCrumb) { args.Settings.AdditionalWebForms.Insert(0, new KeyValuePair <string, string>(".yficrumb", args.Settings.Account.Crumb)); } if (args.Settings.RefererUrlPart.StartsWith("http")) { args.Settings.Url = args.Settings.RefererUrlPart; } else { args.Settings.Url = "http://" + new Uri(args.Settings.Url).Host + args.Settings.RefererUrlPart; } dl.Settings.UrlString = args.Settings.Url; dl.Settings.Account = args.Settings.Account; StringBuilder postData = new StringBuilder(); bool isFirst = true; foreach (var kvp in args.Settings.AdditionalWebForms) { string data = Uri.EscapeDataString(kvp.Key) + "=" + Uri.EscapeDataString(kvp.Value); if (isFirst) { isFirst = false; } else { data = "&" + data; } postData.Append(data); } dl.Settings.PostStringData = postData.ToString(); } }
private void UploadAsync2(AsyncArgs args) { PostDataUpload dl = new PostDataUpload(); this.PrepareDownloader(dl, args); if (dl.Settings.PostStringData != string.Empty) { dl.AsyncDownloadCompleted += this.dl_DownloadAsyncCompleted; dl.DownloadAsync(args.UserArgs); } }