コード例 #1
0
        // Set request headers
        private static void SetRequestHeaders(HttpWebRequest webRequest, ServiceRequest serviceRequest,
                                              ClientConfiguration configuration)
        {
            webRequest.Timeout          = configuration.ConnectionTimeout;
            webRequest.ReadWriteTimeout = configuration.ConnectionTimeout;
            webRequest.Method           = serviceRequest.Method.ToString().ToUpperInvariant();

            // Because it is not allowed to set common headers
            // with the WebHeaderCollection.Add method,
            // we have to call an internal method to skip validation.
            foreach (var h in serviceRequest.Headers)
            {
                // Nginx does not accept a chunked encoding request with Content-Length, as detailed in #OSS-2848
                if (h.Key.Equals(HttpHeaders.ContentLength) && (serviceRequest.UseChunkedEncoding ||
                                                                (serviceRequest.Content != null && !serviceRequest.Content.CanSeek) || serviceRequest.Content == null))
                {
                    continue;
                }

                HttpExtensions.AddInternal(webRequest.Headers, h.Key, h.Value);
            }

            // Set user-agent
            if (!string.IsNullOrEmpty(configuration.UserAgent))
            {
                webRequest.UserAgent = configuration.UserAgent;
            }
        }
コード例 #2
0
        // Set request headers
        private static void SetRequestHeaders(HttpWebRequest webRequest, ServiceRequest serviceRequest,
                                              ClientConfiguration configuration)
        {
            webRequest.Timeout = configuration.ConnectionTimeout;
            webRequest.Method  = serviceRequest.Method.ToString().ToUpperInvariant();

            // Because it is not allowed to set common headers
            // with the WebHeaderCollection.Add method,
            // we have to call an internal method to skip validation.
            foreach (var h in serviceRequest.Headers)
            {
                HttpExtensions.AddInternal(webRequest.Headers, h.Key, h.Value);
            }

            // Set user-agent
            if (!string.IsNullOrEmpty(configuration.UserAgent))
            {
                webRequest.UserAgent = configuration.UserAgent;
            }
        }