Beispiel #1
0
        // Set request headers
        private static void SetRequestHeaders(HttpWebRequest webRequest, ServiceRequest serviceRequest,
                                              ClientConfiguration configuration)
        {
            webRequest.Timeout          = configuration.ConnectionTimeout;
            webRequest.ReadWriteTimeout = configuration.ReadWriteTimeout;
            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)
            {
                if (h.Key.CompareTo(LogConsts.NAME_HEADER_HOST) == 0)
                {
                    webRequest.Host = h.Value;
                }
                else if (h.Key.CompareTo(LogConsts.NAME_HEADER_DATE) == 0)
                {
                    webRequest.Date = DateUtils.ParseRfc822Date(h.Value);
                }
                if (h.Key.CompareTo(LogConsts.NAME_HEADER_CONTENTTYPE) == 0)
                {
                    webRequest.ContentType = h.Value;
                }
                else
                {
                    webRequest.Headers.AddInternal(h.Key, h.Value);
                }
            }

            // Set user-agent
            if (!string.IsNullOrEmpty(configuration.UserAgent))
            {
                webRequest.UserAgent = configuration.UserAgent;
            }
        }
 protected abstract ServiceResponse SendCore(ServiceRequest request, ExecutionContext context);