public RequestDescription GetRequestDescription() { if (string.IsNullOrEmpty(_context.Signature)) { _consumerContext.SignContext(_context); } Uri uri = _context.GenerateUri(); var description = new RequestDescription { Url = uri, Method = _context.RequestMethod }; if ((_context.FormEncodedParameters != null) && (_context.FormEncodedParameters.Count > 0)) { description.ContentType = Parameters.HttpFormEncoded; description.Body = UriUtility.FormatQueryString(_context.FormEncodedParameters.ToQueryParametersExcludingTokenSecret()); } else if (!string.IsNullOrEmpty(RequestBody)) { description.Body = UriUtility.UrlEncode(RequestBody); } else if (RequestStream != null) { description.RequestStream = RequestStream; } if (_consumerContext.UseHeaderForOAuthParameters) { description.Headers[Parameters.OAuth_Authorization_Header] = _context.GenerateOAuthParametersForHeader(); } return(description); }
public RequestDescription GetRequestDescription() { if (string.IsNullOrEmpty(_context.Signature)) { _consumerContext.SignContext(_context); } Uri uri = _context.GenerateUri(); var description = new RequestDescription { Url = uri, Method = _context.RequestMethod }; if ((_context.FormEncodedParameters != null) && (_context.FormEncodedParameters.Count > 0)) { description.ContentType = Parameters.HttpFormEncoded; description.Body = UriUtility.FormatQueryString(_context.FormEncodedParameters.ToQueryParametersExcludingTokenSecret()); } else if (!string.IsNullOrEmpty(RequestBody)) { description.Body = UriUtility.UrlEncode(RequestBody); } else if (RequestStream != null) { description.RequestStream = RequestStream; } if (_consumerContext.UseHeaderForOAuthParameters) { description.Headers[Parameters.OAuth_Authorization_Header] = _context.GenerateOAuthParametersForHeader(); } return description; }
public virtual HttpWebRequest ToWebRequest() { RequestDescription description = GetRequestDescription(); var request = (HttpWebRequest)WebRequest.Create(description.Url); request.Method = description.Method; request.UserAgent = _consumerContext.UserAgent; request.ContentType = description.ContentType; if (!string.IsNullOrEmpty(AcceptsType)) { request.Accept = AcceptsType; } try { if (Context.Headers["If-Modified-Since"] != null) { string modifiedDateString = Context.Headers["If-Modified-Since"]; request.IfModifiedSince = DateTime.Parse(modifiedDateString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } } catch (Exception ex) { throw new ApplicationException("If-Modified-Since header could not be parsed as a datetime", ex); } if (ProxyServerUri != null) { request.Proxy = new WebProxy(ProxyServerUri, false); } if (description.ContentType == Parameters.HttpFormEncoded) { using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(description.Body); } } else if (!string.IsNullOrEmpty(description.Body)) { using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(description.Body); } } else if (description.RequestStream != null) { using (var requestStream = request.GetRequestStream()) { description.RequestStream.CopyTo(requestStream); } } if (description.Headers.Count > 0) { foreach (string key in description.Headers.AllKeys) { request.Headers[key] = description.Headers[key]; } } // Attach a client ssl certificate to the HttpWebRequest if (_clientSslCertificateFactory != null) { X509Certificate2 certificate = _clientSslCertificateFactory.CreateCertificate(); if (certificate != null) { request.ClientCertificates.Add(certificate); } } return(request); }
public virtual HttpWebRequest ToWebRequest() { RequestDescription description = GetRequestDescription(); var request = (HttpWebRequest)WebRequest.Create(description.Url); request.Method = description.Method; request.UserAgent = _consumerContext.UserAgent; if (Timeout.HasValue) { request.Timeout = Timeout.Value; } if (!string.IsNullOrEmpty(AcceptsType)) { request.Accept = AcceptsType; } try { if (Context.Headers["If-Modified-Since"] != null) { string modifiedDateString = Context.Headers["If-Modified-Since"]; request.IfModifiedSince = DateTime.Parse(modifiedDateString); } } catch (Exception ex) { throw new ApplicationException("If-Modified-Since header could not be parsed as a datetime", ex); } if (ProxyServerUri != null) { request.Proxy = new WebProxy(ProxyServerUri, false); } if (!string.IsNullOrEmpty(description.Body)) { request.ContentType = description.ContentType; using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(description.Body); } } else if (description.RawBody != null && description.RawBody.Length > 0) { request.ContentType = description.ContentType; using (var writer = new BinaryWriter(request.GetRequestStream())) { writer.Write(description.RawBody); } } if (description.Headers.Count > 0) { foreach (string key in description.Headers.AllKeys) { request.Headers[key] = description.Headers[key]; } } return(request); }
public virtual HttpWebRequest ToWebRequest() { RequestDescription description = GetRequestDescription(); var request = (HttpWebRequest)WebRequest.Create(description.Url); request.Timeout = (int)TimeSpan.FromMinutes(3).TotalMilliseconds; request.Method = description.Method; request.UserAgent = _consumerContext.UserAgent; if (!string.IsNullOrEmpty(AcceptsType)) { request.Accept = AcceptsType; } DateTime?ifModifiedSinceDate = ParseIfModifiedSince(Context); if (ifModifiedSinceDate.HasValue) { request.IfModifiedSince = ifModifiedSinceDate.Value; } if (ProxyServerUri != null) { request.Proxy = new WebProxy(ProxyServerUri, false); } if (description.ContentType == Parameters.HttpFormEncoded) { request.ContentType = description.ContentType; using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(description.Body); } } else if (!string.IsNullOrEmpty(description.Body)) { using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(description.Body); } } else if (description.RequestStream != null) { using (var requestStream = request.GetRequestStream()) { description.RequestStream.CopyTo(requestStream); } } if (description.Headers.Count > 0) { foreach (string key in description.Headers.AllKeys) { request.Headers[key] = description.Headers[key]; } } // Attach a client ssl certificate to the HttpWebRequest if (_clientSslCertificateFactory != null) { X509Certificate2 certificate = _clientSslCertificateFactory.CreateCertificate(); if (certificate != null) { request.ClientCertificates.Add(certificate); } } return(request); }