コード例 #1
0
        public async Task <IHttpResponseModel> Execute(IHttpRequestModel httpRequest)
        {
            if (!(httpRequest is HttpRequestModel request))
            {
                throw new ArgumentException("Client does not support request object type");
            }

            IHttpResponseModel response = null;
            Exception          caughtEx = null;

            try
            {
                ValidateRequest(request);

                response = await Send(request);

                return(response);
            }
            catch (Exception ex)
            {
                caughtEx = ex;

                throw;
            }
            finally
            {
                CommunicationLoggerEventManager.NotifyHttpRequestCompleted(
                    this, new HttpCommunicationEventArgs(request, response, caughtEx));
            }
        }
コード例 #2
0
        private string FormatResponseForLog(IHttpResponseModel response)
        {
            var sb = new StringBuilder();

            sb.AppendLine("API Response:");
            sb.AppendLine();

            FormatAndPrintHeaders(sb, response.Headers);

            if (response.IsBodyInMemory)
            {
                string responseBody = response.GetBodyAsString();
                if (!string.IsNullOrWhiteSpace(responseBody))
                {
                    sb.AppendLine();
                    sb.AppendLine(responseBody);
                }
            }

            return(sb.ToString());
        }
コード例 #3
0
 public HttpCommunicationEventArgs(IHttpRequestModel request, IHttpResponseModel response, Exception caughtEx)
 {
     Request         = request;
     Response        = response;
     CaughtException = caughtEx;
 }