示例#1
0
        private WebRequest Compose(string uri, RequestSettings settings, IDictionary <HttpRequestHeader, string> headers, string postData)
        {
            var request = Compose(uri, settings, headers, null, postData);

            HttpWebRequestHelper.WriteStringToRequestStream(request, postData);
            return(request);
        }
示例#2
0
        private WebRequest Compose(string uri, RequestSettings settings, IDictionary <HttpRequestHeader, string> headers, IDictionary <string, string> customHeaders, string postData)
        {
            //var url = new Uri (uri);
            var request = (HttpWebRequest)WebRequest.Create(uri);

            if (settings != null)
            {
                request.Method = settings.Method.ToString().ToUpper();
            }

            if (headers != null)
            {
                foreach (var header in headers)
                {
                    switch (header.Key)
                    {
                    case HttpRequestHeader.UserAgent:
                        request.UserAgent = headers[HttpRequestHeader.UserAgent];
                        break;

                    case HttpRequestHeader.ContentType:
                        request.ContentType = headers[HttpRequestHeader.ContentType];
                        break;

                    case HttpRequestHeader.Authorization:
                        request.Headers.Add(HttpRequestHeader.Authorization, headers[HttpRequestHeader.Authorization]);
                        break;

                    case HttpRequestHeader.Accept:
                        request.Accept = headers[HttpRequestHeader.Accept];
                        break;
                    }
                }
            }

            if (customHeaders != null)
            {
                foreach (var header in customHeaders)
                {
                    request.Headers.Add(header.Key, header.Value);
                }
            }

            if (!string.IsNullOrEmpty(postData))
            {
                HttpWebRequestHelper.WriteStringToRequestStream(request, postData);
            }

            return(request);
        }
示例#3
0
        private void Notify(Guid messageId, HttpResponse response)
        {
            var trace = new WebMessageTrace(messageId)
            {
                Messages = new List <WebMessage>
                {
                    new WebMessage(WebMessageType.Response)
                    {
                        Details = response.Data,
                        Headers = HttpWebRequestHelper.GetHeaders(response.Headers)
                    }
                }
            };

            Publish(trace);
        }
示例#4
0
        private void Notify(Guid messageId, WebException exception)
        {
            var trace = new WebMessageTrace(messageId)
            {
                Messages = new List <WebMessage>
                {
                    new WebMessage(WebMessageType.Error)
                    {
                        Details = string.Format("Message - {0} Stack Trace - {1}", exception.Message, exception.StackTrace),
                        Headers = HttpWebRequestHelper.GetHeaders(exception.Response.Headers)
                    }
                }
            };

            Publish(trace);
        }
示例#5
0
        private void Notify(Guid messageId, WebRequest request, string data)
        {
            var trace = new WebMessageTrace(messageId)
            {
                Messages = new List <WebMessage>
                {
                    new WebMessage(WebMessageType.Request)
                    {
                        Details      = data,
                        Headers      = HttpWebRequestHelper.GetHeaders(request.Headers),
                        Method       = request.Method,
                        AbsolutePath = request.RequestUri.AbsolutePath
                    }
                }
            };

            Publish(trace);
        }
示例#6
0
        private void Notify(Guid messageId, HttpRequest request, HttpResponse response, Exception exception)
        {
            var trace = new WebMessageTrace(messageId);

            if (response != null)
            {
                trace.Messages.Add(
                    new WebMessage(WebMessageType.Response)
                {
                    Details   = response.Data,
                    Headers   = HttpWebRequestHelper.GetHeaders(response.Headers),
                    Timestamp = DateTime.UtcNow
                });
            }

            if (request != null)
            {
                trace.Server = request.Server;
                trace.Messages.Add(
                    new WebMessage(WebMessageType.Request)
                {
                    Details      = request.Data,
                    Headers      = HttpWebRequestHelper.GetHeaders(request.Headers),
                    Method       = request.Request.Method,
                    AbsolutePath = request.Request.RequestUri.AbsolutePath,
                    Timestamp    = request.Timestamp
                });
            }
            if (exception != null)
            {
                trace.Messages.Add(
                    new WebMessage(WebMessageType.Error)
                {
                    Details   = string.Format("Message - {0} Stack Trace - {1}", exception.Message, exception.StackTrace),
                    Headers   = exception.GetType() == typeof(WebException) && ((WebException)exception).Response != null ? HttpWebRequestHelper.GetHeaders(((WebException)exception).Response.Headers) : new Dictionary <string, string>(),
                    Timestamp = DateTime.UtcNow
                });
            }

            Publish(trace);
        }
示例#7
0
 private HttpResponse GetResponse(WebRequest request)
 {
     return(HttpWebRequestHelper.GetResponseFromServer(request));
 }