public HttpWebRequest Create(string uri) { FormData formData = new FormData(false, "Email", _username, "Passwd", _password, "service", _service, "source", _source); if (_captchaToken != null && _captchaValue != null) { formData.Add("logintoken", _captchaToken); formData.Add("logincaptcha", _captchaValue); } HttpWebRequest request = HttpRequestHelper.CreateHttpWebRequest(uri, true); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; using (Stream inStream = formData.ToStream()) using (Stream outStream = request.GetRequestStream()) StreamHelper.Transfer(inStream, outStream); return(request); }
public HttpWebRequest Create(string uri) { // TODO: choose rational timeout values HttpWebRequest request = HttpRequestHelper.CreateHttpWebRequest(uri, false); _parent.CreateAuthorizationFilter().Invoke(request); request.ContentType = MimeHelper.GetContentType(Path.GetExtension(_filename)); try { request.Headers.Add("Slug", Path.GetFileNameWithoutExtension(_filename)); } catch (ArgumentException) { request.Headers.Add("Slug", "Image"); } request.Method = _method; using (Stream s = request.GetRequestStream()) { using (Stream inS = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { StreamHelper.Transfer(inS, s); } } return(request); }
public async Task <HttpRequestMessage> Create(string uri) { // TODO: ETag support required?? // TODO: choose rational timeout values var request = HttpRequestHelper.CreateHttpWebRequest(uri, false); //request.AllowWriteStreamBuffering = _allowWriteStreamBuffering; if (_etag != null && _etag.Length != 0) { request.Headers["If-match"] = _etag; } await _parent._requestFilter(request); using (Stream inS = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { var streamContent = new HttpStreamContent(inS.AsInputStream()); streamContent.Headers.ContentType = HttpMediaTypeHeaderValue.Parse(MimeHelper.GetContentType(Path.GetExtension(_filename))); if (_parent._options != null && _parent._options.SupportsSlug) { request.Headers["Slug"] = Path.GetFileNameWithoutExtension(_filename); } request.Method = new HttpMethod(_method); } return(request); }
/// <summary> /// "It looks like the problem with the inline image is due to referrer checking. /// The thumbnail image being used is protected for display only on certain domains. /// These domains include *.blogspot.com and *.google.com. This user is using a /// feature in Blogger which allows him to display his blog directly on his own /// domain, which will not pass the referrer checking. /// /// "The maximum size of a thumbnail image that can be displayed on non-*.blogspot.com /// domains is 800px. (blogs don't actually appear at *.google.com). However, if you /// request a 800px thumbnail, and the image is less than 800px for the maximum /// dimension, then the original image will be returned without the referrer /// restrictions. That sounds like it will work for you, so feel free to give it a /// shot and let me know if you have any further questions or problems." /// -- Anonymous Google Employee /// </summary> private async Task <string> PicasaRefererBlockingWorkaround(string blogId, FileUploadRole role, string srcUrl) { if (role == FileUploadRole.LinkedImage && Options.UsePicasaS1600h) { try { int lastSlash = srcUrl.LastIndexOf('/'); string srcUrl2 = srcUrl.Substring(0, lastSlash) + "/s1600-h" + srcUrl.Substring(lastSlash); var req = HttpRequestHelper.CreateHttpWebRequest(srcUrl2, true); req.Method = HttpMethod.Head; await req.Content.BufferAllAsync(); srcUrl = srcUrl2; return(srcUrl); } catch (WebException we) { Debug.Fail("Picasa s1600-h hack failed: " + we.ToString()); } } try { srcUrl += ((srcUrl.IndexOf('?') >= 0) ? "&" : "?") + "imgmax=800"; } catch (Exception ex) { Debug.Fail("Unexpected error while doing Picasa upload: " + ex.ToString()); } return(srcUrl); }
private HttpRequestMessage CreateRequest(string mode, string challenge, params string[] addlParams) { var request = HttpRequestHelper.CreateHttpWebRequest(ENDPOINT, true, Timeout.Infinite, Timeout.Infinite); request.Headers["X-FB-User"] = username; if (challenge != null) { request.Headers["X-FB-Auth"] = CreateAuthString(challenge); } request.Headers["X-FB-Mode"] = mode; if (addlParams != null) { for (int i = 0; i < addlParams.Length; i += 2) { string name = addlParams[i]; string value = addlParams[i + 1]; if (name != null) { request.Headers["X-FB-" + name] = value; } } } return(request); }
public void CancelPublish() { Cancel(); try { if (_stream != null) { _stream.Cancel(); _stream.Dispose(); _stream = null; } } catch (NullReferenceException) { } if (!string.IsNullOrEmpty(_updateUrl)) { HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest(_updateUrl, true, -1, -1); YouTubeUploadRequestHelper.AddSimpleHeader(req, _authToken); req.Method = "DELETE"; req.GetResponse().Close(); } }
private static Stream CallYouTubeApi(string requestUrl, int timeoutMs) { // download the document Stream responseStream; try { HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest(requestUrl, true, timeoutMs, timeoutMs); YouTubeUploadRequestHelper.AddSimpleHeader(req, YouTubeAuth.Instance.AuthToken); using (HttpWebResponse response = (HttpWebResponse)req.GetResponse()) { using (Stream responseStreamOrginal = response.GetResponseStream()) { responseStream = StreamHelper.CopyToMemoryStream(responseStreamOrginal); } } } catch (Exception ex) { throw new YouTubeException("YouTube Error", "Unable to download request from YouTube due to the following error: " + ex.Message); } // check for timeout if (responseStream == null) { throw new YouTubeException("Request Timed Out", "The request to YouTube timed out (the service may be unavailable right now)."); } else { return(responseStream); } }
private HttpWebRequest CreateRequest(string mode, string challenge, params string[] addlParams) { HttpWebRequest request = HttpRequestHelper.CreateHttpWebRequest(ENDPOINT, true, Timeout.Infinite, Timeout.Infinite); request.Headers.Add("X-FB-User", username); if (challenge != null) { request.Headers.Add("X-FB-Auth", CreateAuthString(challenge)); } request.Headers.Add("X-FB-Mode", mode); if (addlParams != null) { for (int i = 0; i < addlParams.Length; i += 2) { string name = addlParams[i]; string value = addlParams[i + 1]; if (name != null) { request.Headers.Add("X-FB-" + name, value); } } } return(request); }
/// <summary> /// "It looks like the problem with the inline image is due to referrer checking. /// The thumbnail image being used is protected for display only on certain domains. /// These domains include *.blogspot.com and *.google.com. This user is using a /// feature in Blogger which allows him to display his blog directly on his own /// domain, which will not pass the referrer checking. /// /// "The maximum size of a thumbnail image that can be displayed on non-*.blogspot.com /// domains is 800px. (blogs don't actually appear at *.google.com). However, if you /// request a 800px thumbnail, and the image is less than 800px for the maximum /// dimension, then the original image will be returned without the referrer /// restrictions. That sounds like it will work for you, so feel free to give it a /// shot and let me know if you have any further questions or problems." /// -- Anonymous Google Employee /// </summary> private void PicasaRefererBlockingWorkaround(string blogId, FileUploadRole role, ref string srcUrl) { if (role == FileUploadRole.LinkedImage && Options.UsePicasaS1600h) { try { int lastSlash = srcUrl.LastIndexOf('/'); string srcUrl2 = srcUrl.Substring(0, lastSlash) + "/s1600-h" + srcUrl.Substring(lastSlash); HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest(srcUrl2, true); req.Method = "HEAD"; req.GetResponse().Close(); srcUrl = srcUrl2; return; } catch (WebException we) { Debug.Fail("Picasa s1600-h hack failed: " + we.ToString()); } } try { srcUrl += ((srcUrl.IndexOf('?') >= 0) ? "&" : "?") + "imgmax=800"; } catch (Exception ex) { Trace.Fail("Unexpected error while doing Picasa upload: " + ex.ToString()); } }
public HttpWebRequest Create(string uri) { HttpWebRequest request = HttpRequestHelper.CreateHttpWebRequest(uri, false); request.Method = _method; if (_filter != null) { _filter(request); } return(request); }
public async Task <HttpRequestMessage> Create(string uri) { var request = HttpRequestHelper.CreateHttpWebRequest(uri, false); request.Method = new HttpMethod(_method); if (_filter != null) { await _filter(request); } return(request); }
/// <summary> /// "It looks like the problem with the inline image is due to referrer checking. /// The thumbnail image being used is protected for display only on certain domains. /// These domains include *.blogspot.com and *.google.com. This user is using a /// feature in Blogger which allows him to display his blog directly on his own /// domain, which will not pass the referrer checking. /// /// "The maximum size of a thumbnail image that can be displayed on non-*.blogspot.com /// domains is 800px. (blogs don't actually appear at *.google.com). However, if you /// request a 800px thumbnail, and the image is less than 800px for the maximum /// dimension, then the original image will be returned without the referrer /// restrictions. That sounds like it will work for you, so feel free to give it a /// shot and let me know if you have any further questions or problems." /// -- Anonymous Google Employee /// </summary> private void PicasaRefererBlockingWorkaround(string blogId, FileUploadRole role, ref string srcUrl) { if (role == FileUploadRole.LinkedImage && Options.UsePicasaS1600h) { try { int lastSlash = srcUrl.LastIndexOf('/'); string srcUrl2 = srcUrl.Substring(0, lastSlash) + "/s1600-h" + srcUrl.Substring(lastSlash); HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest(srcUrl2, true); req.Method = "HEAD"; req.GetResponse().Close(); srcUrl = srcUrl2; return; } catch (WebException we) { Debug.Fail("Picasa s1600-h hack failed: " + we.ToString()); } } try { if (!Options.UsePicasaImgMaxAlways) { // This class doesn't have access to the homePageUrl, so this is a workaround to // to get the homePageUrl while minimizing the amount of code we have to change (we're at MShip/ZBB) foreach (string id in BlogSettings.GetBlogIds()) { using (BlogSettings settings = BlogSettings.ForBlogId(id)) { if (settings.ClientType == "BloggerAtom" && settings.HostBlogId == blogId) { switch (UrlHelper.GetDomain(settings.HomepageUrl).ToUpperInvariant()) { case "BLOGSPOT.COM": case "GOOGLE.COM": return; } } } } } srcUrl += ((srcUrl.IndexOf('?') >= 0) ? "&" : "?") + "imgmax=800"; } catch (Exception ex) { Trace.Fail("Unexpected error while doing Picasa upload: " + ex.ToString()); } }
public async Task <HttpRequestMessage> Create(string uri) { var request = HttpRequestHelper.CreateHttpWebRequest(uri, true); request.Method = new HttpMethod(_method); // request.KeepAlive = true; // request.Pipelined = true; if (_etag != null && _etag != "") { request.Headers["If-match"] = _etag; } request.Content = new HttpStringContent(_doc.DocumentElement.GetXml()); if (_contentType != null) { if (request.Content.Headers.ContentType != null) { request.Content.Headers.ContentType.MediaType = _contentType; } } if (_filter != null) { await _filter(request); } Debug.WriteLine( string.Format(CultureInfo.InvariantCulture, "XML REST request:\r\n{0} {1}\r\n{2}\r\n{3}", _method, uri, (_etag != null && _etag != "") ? "If-match: " + _etag : "(no etag)", _doc.GetXml())); //using (Stream s = await request.GetRequestStreamAsync()) //{ // var writer = System.Xml.XmlWriter.Create(s, new XmlWriterSettings() {Encoding = _encodingToUse, Indent = true, IndentChars = " "}); // await writer.WriteRawAsync(_doc.DocumentElement.GetXml()); // await writer.FlushAsync(); //} return(request); }
public async Task <HttpRequestMessage> Create(string uri) { var req = HttpRequestHelper.CreateHttpWebRequest(uri, true); _multipartMimeRequestHelper.Init(req); if (_filter != null) { await _filter(req); } _multipartMimeRequestHelper.Open(); _multipartMimeRequestHelper.AddXmlRequest(_xmlDoc); _multipartMimeRequestHelper.AddFile(_filename); _multipartMimeRequestHelper.Close(); using (var stream = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { return(await _multipartMimeRequestHelper.SendRequest(stream)); } }
public HttpWebRequest Create(string uri) { HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest(uri, true); _multipartMimeRequestHelper.Init(req); if (_filter != null) { _filter(req); } _multipartMimeRequestHelper.Open(); _multipartMimeRequestHelper.AddXmlRequest(_xmlDoc); _multipartMimeRequestHelper.AddFile(_filename); _multipartMimeRequestHelper.Close(); using (CancelableStream stream = new CancelableStream(new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read))) { return(_multipartMimeRequestHelper.SendRequest(stream)); } }
public HttpWebRequest Create(string uri) { HttpWebRequest request = HttpRequestHelper.CreateHttpWebRequest(uri, true); request.Method = _method; // request.KeepAlive = true; // request.Pipelined = true; if (_etag != null && _etag != "") { request.Headers["If-match"] = _etag; } if (_contentType != null) { request.ContentType = _contentType; } if (_filter != null) { _filter(request); } if (ApplicationDiagnostics.VerboseLogging) { Trace.WriteLine( string.Format(CultureInfo.InvariantCulture, "XML REST request:\r\n{0} {1}\r\n{2}\r\n{3}", _method, uri, (_etag != null && _etag != "") ? "If-match: " + _etag : "(no etag)", _doc.OuterXml)); } using (Stream s = request.GetRequestStream()) { XmlTextWriter writer = new XmlTextWriter(s, _encodingToUse); writer.Formatting = Formatting.Indented; writer.Indentation = 1; writer.IndentChar = ' '; writer.WriteStartDocument(); _doc.DocumentElement.WriteTo(writer); writer.Close(); } return(request); }
private bool IsVideoComepleted() { // Send a request to get the status HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest(_updateUrl, true, -1, -1); YouTubeUploadRequestHelper.AddSimpleHeader(req, _authToken); string innerResult; using (HttpWebResponse response = (HttpWebResponse)req.GetResponse()) { using (StreamReader responseReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { innerResult = responseReader.ReadToEnd(); } } // Find the status elemnt XmlDocument xmlDoc = new XmlDocument(NamespaceManager.NameTable); xmlDoc.LoadXml(innerResult); XmlNode stateNode = xmlDoc.SelectSingleNode("//atom:entry/app:control/yt:state", NamespaceManager); // If there is no element with status, then the video is completed if (stateNode == null) { _status = VideoPublishStatus.Completed; _message = Res.Get("Video" + _status); return(true); } // Check to make sure the video doesnt have a bad status string value = stateNode.Attributes["name"] != null ? stateNode.Attributes["name"].Value : ""; if (value == "rejected" || value == "failed") { throw new Exception(Res.Get("YouTube" + stateNode.Attributes["reasonCode"].Value)); } return(false); }
private string Upload() { HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads", true, -1, -1); YouTubeUploadRequestHelper uploader = new YouTubeUploadRequestHelper(req); uploader.AddHeader(_authToken, Path.GetFileName(Path.GetFileName(_filePath))); uploader.Open(); uploader.AddXmlRequest(_title, _description, _tags, _categoryId, _permissionValue); uploader.AddFile(_filePath); uploader.Close(); try { using (_stream = new CancelableStream(new FileStream(_filePath, FileMode.Open, FileAccess.Read, FileShare.Read))) { uploader.SendRequest(_stream); } } finally { _stream = null; } string result; using (HttpWebResponse response = (HttpWebResponse)req.GetResponse()) { using (StreamReader responseReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { result = responseReader.ReadToEnd(); } } return(result); }
public async Task <HttpRequestMessage> Create(string uri) { // TODO: choose rational timeout values var request = HttpRequestHelper.CreateHttpWebRequest(uri, false); await(await _parent.CreateAuthorizationFilter()).Invoke(request); //request.Headers. //request.ContentType = MimeHelper.GetContentType(Path.GetExtension(_filename)); try { request.Headers.Add("Slug", Path.GetFileNameWithoutExtension(_filename)); } catch (ArgumentException) { request.Headers.Add("Slug", "Image"); } request.Method = new HttpMethod(_method); _fileStream.Seek(0, SeekOrigin.Begin); var streamContent = new HttpStreamContent(_fileStream.AsInputStream()); streamContent.Headers.ContentLength = (ulong?)_fileStream.Length; streamContent.Headers.ContentType = new HttpMediaTypeHeaderValue(MimeHelper.GetContentType(Path.GetExtension(_filename))); request.Content = streamContent; //using (Stream s = request.GetRequestStream()) //{ // using (Stream inS = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read)) // { // StreamHelper.Transfer(inS, s); // } //} return(request); }
public HttpWebRequest Create(string uri) { // TODO: ETag support required?? // TODO: choose rational timeout values HttpWebRequest request = HttpRequestHelper.CreateHttpWebRequest(uri, false); request.ContentType = MimeHelper.GetContentType(Path.GetExtension(_filename)); if (_parent._options != null && _parent._options.SupportsSlug) { request.Headers.Add("Slug", Path.GetFileNameWithoutExtension(_filename)); } request.Method = _method; request.AllowWriteStreamBuffering = _allowWriteStreamBuffering; if (_etag != null && _etag.Length != 0) { request.Headers.Add("If-match", _etag); } _parent._requestFilter(request); using (Stream inS = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (CancelableStream cs = new CancelableStream(inS)) { request.ContentLength = cs.Length; using (Stream s = request.GetRequestStream()) { StreamHelper.Transfer(cs, s); } } } return(request); }
public void Validate(string urlMapping) { string testFilename = Guid.NewGuid().ToString() + ".txt"; string fromPath = TempFileManager.Instance.CreateTempFile(testFilename); try { _destination.Connect(); try { if (urlMapping != null) { _destination.DoTransfer(fromPath, testFilename, true); } } catch (SiteDestinationException siteException) { throw new DestinationServerFailedException(siteException); } } catch (LoginException) { throw new DestinationLoginFailedException(); } catch (SiteDestinationException siteException) { throw new DestinationServerFailedException(siteException); } if (urlMapping != null) { try { try { if (!urlMapping.EndsWith("/", StringComparison.OrdinalIgnoreCase)) { urlMapping = urlMapping + "/"; } HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest(urlMapping + testFilename, true); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); resp.Close(); } catch (Exception e) { Trace.WriteLine("destination HTTP verification failed: " + e.Message); throw new DestinationUrlMappingFailedException(); } } finally { try { //delete the temp file from the remote server. _destination.DeleteFile(testFilename); } catch (Exception e) { Trace.Fail("destination FTP verification warning: unable to delete test file: " + e.Message); } } } }