Exemplo n.º 1
0
        private static HttpRequestMessage GetHttpRequest(HttpRequestItem item)
        {
            var request = new HttpRequestMessage(new HttpMethod(item.Method.ToString()), item.GetUrl());

            switch (item.Method)
            {
            case HttpMethodType.Post:
            case HttpMethodType.Put:
            case HttpMethodType.Delete:
            case HttpMethodType.Head:
            case HttpMethodType.Options:
            case HttpMethodType.Trace:
                request.Content = new StringContent(item.RawData, item.EncodingType, item.ContentType);
                break;

            case HttpMethodType.Get:
            default:
                break;
            }
            foreach (var header in item.HeaderMap.Where(h => !NotAddHeaderNames.Contains(h.Key)))
            {
                request.Headers.Add(header.Key, header.Value);
            }
            return(request);
        }
Exemplo n.º 2
0
        private HttpRequestMessage GetHttpRequest(HttpRequestItem item)
        {
            var request = new HttpRequestMessage(new HttpMethod(item.Method.ToString().ToUpper()), item.GetUrl());

            switch (item.Method)
            {
            case HttpMethodType.Post:
            case HttpMethodType.Put:
            case HttpMethodType.Delete:
            case HttpMethodType.Head:
            case HttpMethodType.Options:
            case HttpMethodType.Trace:
                request.Content = new StringContent(item.RawData, item.EncodingType, item.ContentType);
                break;

            case HttpMethodType.Get:
            default:
                break;
            }
            foreach (var header in item.HeaderMap.Where(h => !NotAddHeaderNames.Contains(h.Key)))
            {
                request.Headers.Add(header.Key, header.Value);
            }
            var cookies = item.HeaderMap.GetOrDefault(HttpConstants.Cookie);

            if (!cookies.IsNullOrEmpty())
            {
                _cookieContainer.SetCookies(request.RequestUri, cookies);
            }
            return(request);
        }