ToString() public method

public ToString ( ) : string
return string
        private static string GetExceptionMessage(HttpResponseMessage responseMessage)
        {
            if (responseMessage == null)
            {
                throw new ArgumentNullException("responseMessage");
            }

            return responseMessage.ToString();
        }
		public static async Task PrintResponse (HttpResponseMessage response)
		{
			Debug ("RESPONSE:");
			Debug (response.ToString ());
			if (response.Content != null) {
				var respBody = await response.Content.ReadAsStringAsync ();
				Debug (respBody.Substring (0, Math.Min (MaxBodyLength, respBody.Length)) + (respBody.Length >= MaxBodyLength ? "(...)" : ""));
			}
		}
Example #3
0
        public async Task SetResponseAsync(HttpResponseMessage httpResponseMessage)
        {
            _stopwatch.Stop();

            _responseLog.Headers = httpResponseMessage.ToString();
            _responseLog.StatusCode = httpResponseMessage.StatusCode;

            if (httpResponseMessage.Content != null)
            {
                _responseLog.Body = await httpResponseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
            }
        }
 protected override HttpResponseMessage ProcessResponse(HttpResponseMessage response, CancellationToken cancellationToken)
 {
     if (response != null)
     {
         this.logger.LogMessage(response.ToString(), Severity.Informational, Verbosity.Detailed);
         if (response.Content != null)
         {
             this.logger.LogMessage(string.Format(CultureInfo.InvariantCulture, "Payload: {0} ", response.Content.ReadAsStringAsync().Result), Severity.Informational, Verbosity.Detailed);
         }
     }
     return response;
 }
Example #5
0
		public void Ctor_Default ()
		{
			var m = new HttpResponseMessage ();
			Assert.IsNull (m.Content, "#1");
			Assert.IsNotNull (m.Headers, "#2");
			Assert.IsTrue (m.IsSuccessStatusCode, "#3");
			Assert.AreEqual ("OK", m.ReasonPhrase, "#4");
			Assert.IsNull (m.RequestMessage, "#5");
			Assert.AreEqual (HttpStatusCode.OK, m.StatusCode, "#6");
			Assert.AreEqual (new Version (1, 1), m.Version, "#7");
			Assert.IsNull (m.Headers.CacheControl, "#8");

			Assert.AreEqual ("StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: <null>, Headers:\r\n{\r\n}", m.ToString (), "#9");
		}
Example #6
0
 public static void LogResponseOnFailedAssert(this ILogger logger, HttpResponseMessage response, string responseText, Action assert)
 {
     try
     {
         assert();
     }
     catch (XunitException)
     {
         logger.LogWarning(response.ToString());
         if (!string.IsNullOrEmpty(responseText))
         {
             logger.LogWarning(responseText);
         }
         throw;
     }
 }
Example #7
0
 public void ReceiveResponse(string invocationId, HttpResponseMessage response)
 {
     Write("{0}: ReceiveResponse {1}", invocationId, response.ToString());
 }
Example #8
0
		public void Headers_ConnectionClose ()
		{
			HttpResponseMessage message = new HttpResponseMessage ();
			HttpResponseHeaders headers = message.Headers;
			Assert.IsNull (headers.ConnectionClose, "#1");

			headers.ConnectionClose = false;
			Assert.IsFalse (headers.ConnectionClose.Value, "#2");

			headers.Clear ();

			headers.ConnectionClose = true;
			Assert.IsTrue (headers.ConnectionClose.Value, "#3");

			headers.Clear ();
			headers.Connection.Add ("Close");
			Assert.IsTrue (headers.ConnectionClose.Value, "#4");

			Assert.AreEqual ("StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: <null>, Headers:\r\n{\r\nConnection: Close\r\n}", message.ToString (), "#5");
		}
        public void Headers_ConnectionClose()
        {
            HttpResponseMessage message = new HttpResponseMessage ();
            HttpResponseHeaders headers = message.Headers;
            Assert.IsNull (headers.ConnectionClose, "#1");

            headers.ConnectionClose = false;
            Assert.IsFalse (headers.ConnectionClose.Value, "#2");

            headers.Clear ();

            headers.ConnectionClose = true;
            Assert.IsTrue (headers.ConnectionClose.Value, "#3");

            headers.Clear ();
            headers.Connection.Add ("Close");
            Assert.IsTrue (headers.ConnectionClose.Value, "#4");

            // .NET encloses the "Connection: Close" with two whitespaces.
            var normalized = Regex.Replace (message.ToString (), @"\s", "");
            Assert.AreEqual ("StatusCode:200,ReasonPhrase:'OK',Version:1.1,Content:<null>,Headers:{Connection:Close}", normalized, "#5");
        }
 private static void Format(StringBuilder message, HttpResponseMessage response, string header)
 {
     HandleErrorHelper.AppendHeader(message, header);
     message.AppendLine(response == null ? HandleErrorHelper.NULL : response.ToString());
     message.AppendLine();
 }
Example #11
0
        internal static void ClientSendCompleted(HttpClient httpClient, HttpResponseMessage response, HttpRequestMessage request)
        {
            if (!s_log.IsEnabled())
            {
                return;
            }

            string responseString = "";
            if (response != null)
            {
                responseString = response.ToString();
            }

            s_log.ClientSendCompleted(LoggingHash.HashInt(request), LoggingHash.HashInt(response), responseString, LoggingHash.HashInt(httpClient));
        }
Example #12
0
        protected PayPalPaymentData ExecutePayment(PayPalOAuthTokenData token, string payPalPaymentId, string payer_id, bool useSandbox)
        {
            if (string.IsNullOrEmpty(token.access_token))
            {
                throw new ArgumentNullException("token.access_token");
            }
            if (string.IsNullOrEmpty(payPalPaymentId))
            {
                throw new ArgumentNullException("payPalPaymentId");
            }
            if (string.IsNullOrEmpty(payer_id))
            {
                throw new ArgumentNullException("payer_id");
            }

            PayPalPaymentExecuteData executeData = new PayPalPaymentExecuteData(payer_id);
            string executeJson = JsonConvert.SerializeObject(executeData);
            StringContent postContent = new StringContent(executeJson, Encoding.UTF8, "application/json");

            HttpClient httpClient = new HttpClient();
            httpClient.Timeout = new TimeSpan(0, 0, 30);
            Uri requestUri = null;
            if (useSandbox)
            {
                httpClient.BaseAddress = new Uri("https://api.sandbox.paypal.com/");
            }
            else
            {
                httpClient.BaseAddress = new Uri("https://api.paypal.com/");
            }
            requestUri = new Uri("v1/payments/payment/" + payPalPaymentId + "/execute", UriKind.Relative);

            HttpResponseMessage response = new HttpResponseMessage();
            httpClient.DefaultRequestHeaders.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token);

            try
            {
                response = httpClient.PostAsync(requestUri, postContent).Result;
            }
            catch (Exception ex)
            {
                string message = "HTTP Client returned an error during PayPal Execute Payment API post: " + ex.Message + ". See inner exception for details.";
                throw new Exceptions.PayPalExceptionExecutePaymentFailed(useSandbox, message, null, ex);
            }

            PayPalPaymentData executePaymentResponse;
            if (response.IsSuccessStatusCode)
            {
                //get PayPal data
                string json = response.Content.ReadAsStringAsync().Result;
                try
                {
                    executePaymentResponse = JsonConvert.DeserializeObject<PayPalPaymentData>(json);
                }
                catch (Exception ex)
                {
                    string message = "Error reading PayPal Execute Payment API result! \nError code: " + response.StatusCode + " " + response.ReasonPhrase + "\n" + response.ToString() + " see inner exception for details.\nJSON Response Data: " + json;
                    throw new Exceptions.PayPalExceptionExecutePaymentFailed(useSandbox, message, response, ex);
                }
                executePaymentResponse.Json = json;
            }
            else
            {
                string message = "PayPal Execute Payment API call failed! \nError code: " + response.StatusCode + " " + response.ReasonPhrase + "\n" + response.ToString();
                throw new Exceptions.PayPalExceptionExecutePaymentFailed(useSandbox, message, response, null);
            }

            return executePaymentResponse;
        }
Example #13
0
        public async Task<Exception> GetExceptionFromResponse(HttpResponseMessage response)
        {            
            var result = await response.Content.ReadAsStringAsync();
            var error = JsonConvert.DeserializeObject<Error>(result);

            if (error.Type == null)
            {
                var msg = FormatMessage((int)response.StatusCode, response.ReasonPhrase + ".");
                var exp = new ServiceCallExcepton(msg, response, new Exception(response.ToString())) { HelpLink = GetHelpLink((int)response.StatusCode) };
                return exp;
            }

            var type = Type.GetType(error.Type);

            Exception exception;            
            if (type == null)
            {
                return new ExpectedIssues(_configuration).GetException(ExpectedIssues.ServiceCallError, new Exception(response.ToString()));
            }
            else
            {
                try
                {
                    exception = (Exception)Activator.CreateInstance(type, "The service throw an exception. " + error.Message);
                }
                catch (Exception exp)
                {
                    exception = new InvalidOperationException(error.Message, exp);
                }
            }

            if (error.Data != null)
            {
                foreach (var data in error.Data)
                {
                    exception.Data.Add(data.Key, data.Value);
                }
            }

            return exception;
        }