本文整理汇总了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();
}
示例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 ? "(...)" : ""));
}
}
示例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);
}
}
示例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;
}
示例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");
}
示例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;
}
}
示例7: ReceiveResponse
public void ReceiveResponse(string invocationId, HttpResponseMessage response)
{
Write("{0}: ReceiveResponse {1}", invocationId, response.ToString());
}
示例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");
}
示例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");
}
示例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();
}
示例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));
}
示例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;
}
示例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;
}