当前位置: 首页>>代码示例>>C#>>正文


C# HttpResponseMessage.ToString方法代码示例

本文整理汇总了C#中System.Net.Http.HttpResponseMessage.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseMessage.ToString方法的具体用法?C# HttpResponseMessage.ToString怎么用?C# HttpResponseMessage.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.HttpResponseMessage的用法示例。


在下文中一共展示了HttpResponseMessage.ToString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetExceptionMessage

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

            return responseMessage.ToString();
        }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:9,代码来源:HttpClientException.cs

示例2: PrintResponse

		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 ? "(...)" : ""));
			}
		}
开发者ID:benoitjadinon,项目名称:BlueMarin,代码行数:9,代码来源:LoggingMessageHandler.cs

示例3: SetResponseAsync

        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);
            }
        }
开发者ID:raidenyn,项目名称:yandexdisk.client,代码行数:12,代码来源:Logger.cs

示例4: ProcessResponse

 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;
 }
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:12,代码来源:HttpLoggingHandler.cs

示例5: Ctor_Default

		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");
		}
开发者ID:nkuln,项目名称:mono,代码行数:14,代码来源:HttpResponseMessageTest.cs

示例6: LogResponseOnFailedAssert

 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;
     }
 }
开发者ID:leloulight,项目名称:Entropy,代码行数:16,代码来源:TestServices.cs

示例7: ReceiveResponse

 public void ReceiveResponse(string invocationId, HttpResponseMessage response)
 {
     Write("{0}: ReceiveResponse {1}", invocationId, response.ToString());
 }
开发者ID:mkasek,项目名称:CodeMash2015-1,代码行数:4,代码来源:Program.cs

示例8: Headers_ConnectionClose

		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");
		}
开发者ID:nkuln,项目名称:mono,代码行数:20,代码来源:HttpResponseMessageTest.cs

示例9: Headers_ConnectionClose

        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");
        }
开发者ID:RainsSoft,项目名称:dotnet-httpclient35,代码行数:22,代码来源:HttpResponseMessageTest.cs

示例10: Format

 private static void Format(StringBuilder message, HttpResponseMessage response, string header)
 {
     HandleErrorHelper.AppendHeader(message, header);
     message.AppendLine(response == null ? HandleErrorHelper.NULL : response.ToString());
     message.AppendLine();
 }
开发者ID:wei-zhou,项目名称:diamond,代码行数:6,代码来源:ServiceHandleErrorHelper.cs

示例11: ClientSendCompleted

        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));
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:15,代码来源:HttpEventSource.cs

示例12: ExecutePayment

        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;
        }
开发者ID:berlstone,项目名称:GStore,代码行数:72,代码来源:PayPalPaymentClient.cs

示例13: GetExceptionFromResponse

        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;
        }
开发者ID:Quilt4,项目名称:Quilt4Net,代码行数:41,代码来源:ExpectedIssues.cs


注:本文中的System.Net.Http.HttpResponseMessage.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。