/// <summary> /// Gets the HTTP request. /// </summary> /// <param name="token">If not null, adds the specified ESI token to the headers.</param> /// <param name="dataContentType">The content type of the input data.</param> /// <returns>The HTTP request.</returns> private HttpRequestMessage GetHttpRequest(string token, string dataContentType) { if (m_method == HttpMethod.Get && m_postData != null) { m_url = new Uri($"{m_url.AbsoluteUri}?{m_postData}"); } var request = new HttpRequestMessage { RequestUri = m_url, Method = m_method, }; if (token != null) { // If the token has a space, use that type of auth header string type = "Bearer"; int index = token.IndexOf(' '); if (index > 0) { type = token.Substring(0, index); token = token.Substring(index + 1).TrimStart(); } request.Headers.Authorization = new AuthenticationHeaderValue(type, token); } request.Headers.AcceptCharset.TryParseAdd("ISO-8859-1,utf-8;q=0.8,*;q=0.7"); request.Headers.AcceptLanguage.TryParseAdd("en-us,en;q=0.5"); request.Headers.Pragma.TryParseAdd("no-cache"); request.Headers.UserAgent.TryParseAdd(HttpWebClientServiceState.UserAgent); request.Headers.Accept.ParseAdd(m_accept); if (m_acceptEncoded) { request.Headers.AcceptEncoding.ParseAdd("gzip,deflate;q=0.8"); } if (m_referrer != null) { request.Headers.Referrer = m_referrer; } if (m_postData == null || m_method == HttpMethod.Get) { return(request); } request.Content = new ByteArrayContent(m_postData.Content.ToArray()); if (!string.IsNullOrEmpty(dataContentType)) { request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(dataContentType); } // If we are going to send a compressed request set the appropriate header if (Enum.IsDefined(typeof(DataCompression), m_dataCompression) && m_dataCompression != DataCompression.None) { request.Content.Headers.ContentEncoding.Add(m_dataCompression.ToString().ToLowerInvariant()); } return(request); }
/// <summary> /// Gets the HTTP request. /// </summary> /// <returns></returns> private HttpRequestMessage GetHttpRequest() { if (m_method == HttpMethod.Get && m_postData != null) { m_url = new Uri($"{m_url.AbsoluteUri}?{m_postData}"); } var request = new HttpRequestMessage { RequestUri = m_url, Method = m_method, }; request.Headers.AcceptCharset.TryParseAdd("ISO-8859-1,utf-8;q=0.8,*;q=0.7"); request.Headers.AcceptLanguage.TryParseAdd("en-us,en;q=0.5"); request.Headers.Pragma.TryParseAdd("no-cache"); request.Headers.UserAgent.TryParseAdd(HttpWebClientServiceState.UserAgent); request.Headers.Accept.ParseAdd(m_accept); if (m_acceptEncoded) { request.Headers.AcceptEncoding.ParseAdd("gzip,deflate;q=0.8"); } if (m_referrer != null) { request.Headers.Referrer = m_referrer; } if (m_postData == null || m_method == HttpMethod.Get) { return(request); } request.Content = new ByteArrayContent(m_postData.Content.ToArray()); request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded"); // If we are going to send a compressed request set the appropriate header if (Enum.IsDefined(typeof(DataCompression), m_dataCompression) && m_dataCompression != DataCompression.None) { request.Content.Headers.ContentEncoding .Add(m_dataCompression.ToString().ToLower(CultureConstants.InvariantCulture)); } return(request); }