本文整理汇总了C#中System.Net.Http.HttpRequestMessage.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessage.ToString方法的具体用法?C# HttpRequestMessage.ToString怎么用?C# HttpRequestMessage.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpRequestMessage
的用法示例。
在下文中一共展示了HttpRequestMessage.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getSessionCookieAsync
public async Task<bool> getSessionCookieAsync()
{
Debug.WriteLine("I'm here");
HttpClient request = null;
HttpResponseMessage response = null;
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post,
ApplicationModel.Current.Domain + "/claroline/auth/login.php");
Debug.WriteLine("Message : " + message.ToString());
CallbackArgs args = new CallbackArgs() { login = ApplicationModel.Current.Login, password = ApplicationModel.Current.Password, operation = AllowedOperations.authenticate };
StringContent content = new StringContent(args.ToString());
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded");
message.Content = content;
request = getClient();
response = await request.SendAsync(message);
Debug.WriteLine("getSessionCookie : " + response.StatusCode);
bool empty = String.IsNullOrEmpty(await response.Content.ReadAsStringAsync());
if (empty)
{
CookieCreation = DateTime.Now;
}
Debug.WriteLine("empty : " + empty.ToString());
return empty;
}
示例2: SendAsync
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
string requestString = request.ToString();
string requestBody = "";
if (request.Content != null)
requestBody = await request.Content.ReadAsStringAsync();
bool wasError;
//let other handlers process the request
return await base.SendAsync(request, cancellationToken)
.ContinueWith(task =>
{
string responseBody ="";
if (task.Result.Content != null)
responseBody = task.Result.Content.ReadAsStringAsync().Result;
wasError = task.Result.StatusCode >= HttpStatusCode.BadRequest;
Logger.Instance.WriteToLog("Request: " +
DateTime.UtcNow.ToString("G") + " " + requestString + "\r\n" + "Request body: " + requestBody, wasError);
Logger.Instance.WriteToLog("Response body: " +
DateTime.UtcNow.ToString("G") + " " + responseBody, wasError);
return task.Result;
});
}
示例3: SendAsync
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
CancellationToken cancellationToken)
{
var requestHeaders = request.ToString();
var requestBody = request.Content.ReadAsStringAsync().Result;
var fullRequest = requestHeaders + "\r\n\r\n" + requestBody + "\r\n\r\n";
return base.SendAsync(request, cancellationToken)
.ContinueWith(task =>
{
var response = task.Result;
if (task.Result.StatusCode == HttpStatusCode.InternalServerError || task.Result.StatusCode == HttpStatusCode.BadRequest)
{
var responseHeaders = task.Result.ToString();
var responseBody = task.Result.Content.ReadAsStringAsync().Result;
var fullResponse = responseHeaders + "\r\n\r\n" + responseBody;
response.Content = new StringContent(fullRequest + fullResponse);
}
return response;
}, cancellationToken);
}
示例4: PrintRequest
public static async Task PrintRequest(HttpRequestMessage request){
Debug ("REQUEST:");
Debug (request.ToString ());
if (request.Content != null) {
Debug (await request.Content.ReadAsStringAsync ());
}
}
示例5: Main
private static void Main(string[] args) {
var request =
new HttpRequestMessage(HttpMethod.Get,
new Uri("http://apress.com"));
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html"));
request.Headers.Add("X-Name", "Microsoft");
Console.WriteLine(request.ToString());
Console.ReadLine();
}
示例6: SendAsync
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
Console.WriteLine(request.ToString());
var response = await base.SendAsync(request, cancellationToken);
var msg = string.Format("{0} {1}", response.StatusCode, response.ReasonPhrase);
Console.WriteLine(msg);
return response;
}
示例7: SendAsync
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Utils.WriteLog("Peticion -> " + request.ToString());
var reponse = await base.SendAsync(request, cancellationToken);
Utils.WriteLog("Respuesta -> " + reponse.ToString());
return reponse;
}
示例8: SendAsync
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Utilidades.EscribirLog("Petición--------->>> "+request.ToString());
var response = await base.SendAsync(request, cancellationToken);
Utilidades.EscribirLog("Respuesta-------->>> " + response.ToString());
return response;
}
示例9: SetRequestAsync
public async Task SetRequestAsync(HttpRequestMessage request)
{
_requestLog.Headers = request.ToString();
if (request.Content != null)
{
_requestLog.Body = await request.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
}
_requestLog.StartedAt = DateTime.Now;
_stopwatch.Start();
}
示例10: ProcessRequest
protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request != null)
{
this.logger.LogMessage(request.ToString(), Severity.Informational, Verbosity.Detailed);
if (request.Content != null)
{
this.logger.LogMessage(string.Format(CultureInfo.InvariantCulture, "Payload: {0} ", request.Content.ReadAsStringAsync().Result), Severity.Informational, Verbosity.Detailed);
}
}
return request;
}
示例11: Ctor_Default
public void Ctor_Default ()
{
var m = new HttpRequestMessage ();
Assert.IsNull (m.Content, "#1");
Assert.IsNotNull (m.Headers, "#2");
Assert.AreEqual (HttpMethod.Get, m.Method, "#3");
Assert.IsNotNull (m.Properties, "#4");
Assert.IsNull (m.RequestUri, "#5");
Assert.AreEqual (new Version (1, 1), m.Version, "#6");
Assert.AreEqual ("Method: GET, RequestUri: '<null>', Version: 1.1, Content: <null>, Headers:\r\n{\r\n}", m.ToString (), "#7");
}
示例12: SendAsync
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
if (request.Method == HttpMethod.Trace) {
return Task<HttpResponseMessage>.Factory.StartNew(
() => {
var response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(request.ToString(), Encoding.UTF8, "message/http");
return response;
});
}
return base.SendAsync(request, cancellationToken);
}
示例13: SendAsync
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Trace.WriteLine("Request:");
Trace.WriteLine(request.ToString());
if (request.Content != null)
Trace.WriteLine(await request.Content.ReadAsStringAsync());
var response = await base.SendAsync(request, cancellationToken);
Trace.WriteLine("Response:");
Trace.WriteLine(response.ToString());
if (response.Content != null)
Trace.WriteLine(await response.Content.ReadAsStringAsync());
return response;
}
示例14: SendAsync
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var serialized = new HttpMessageContent(request).ReadAsByteArrayAsync().Result;
var ms = new MemoryStream(serialized);
var request2 = new HttpRequestMessage();
request2.Content = new ByteArrayContent(ms.ToArray());
request2.Content.Headers.Add("Content-Type", "application/http;msgtype=request");
var r3 = request2.Content.ReadAsHttpRequestMessageAsync(cancellationToken).Result;
Console.WriteLine(request.ToString());
Console.WriteLine(r3.ToString());
Console.WriteLine(r3.Content.ReadAsStringAsync().Result);
var response = new HttpResponseMessage(HttpStatusCode.Accepted);
return Task.FromResult(response);
}
示例15: Main
static void Main(string[] args)
{
HttpRequestMessage request = new HttpRequestMessage();
Console.WriteLine(request.ToString());
string a = "dsfsadfa";
a = null;
string tokenDetailsString = string.Empty;
using (StreamReader sr = new StreamReader(""))
{
tokenDetailsString = sr.ReadToEnd();
}
}