本文整理汇总了C#中System.Net.Http.StreamContent.ReadAsHttpRequestMessageAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StreamContent.ReadAsHttpRequestMessageAsync方法的具体用法?C# StreamContent.ReadAsHttpRequestMessageAsync怎么用?C# StreamContent.ReadAsHttpRequestMessageAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.StreamContent
的用法示例。
在下文中一共展示了StreamContent.ReadAsHttpRequestMessageAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static HttpMessage Parse(string data)
{
var httpMessage = new HttpMessage();
HttpContent content;
using (var sr = new StringReader(data))
{
// First line of data is (request|response) followed by a GUID to link request to response
// Rest of data is in message/http format
var firstLine = sr.ReadLine().Split(':');
if (firstLine.Length < 2)
{
throw new ArgumentException("Invalid formatted event :" + data);
}
httpMessage.IsRequest = firstLine[0] == "request";
httpMessage.MessageId = Guid.Parse(firstLine[1]);
var stream = new MemoryStream(Encoding.UTF8.GetBytes(sr.ReadToEnd()));
stream.Position = 0;
content = new StreamContent(stream);
}
var contentType = new MediaTypeHeaderValue("application/http");
content.Headers.ContentType = contentType;
if (httpMessage.IsRequest)
{
contentType.Parameters.Add(new NameValueHeaderValue("msgtype", "request"));
// Using .Result isn't too evil because content is a locally buffered memory stream
// Although if this were hosted in a System.Web based ASP.NET host it might block
httpMessage.HttpRequestMessage = content.ReadAsHttpRequestMessageAsync().Result;
}
else
{
contentType.Parameters.Add(new NameValueHeaderValue("msgtype", "response"));
httpMessage.HttpResponseMessage = content.ReadAsHttpResponseMessageAsync().Result;
}
return httpMessage;
}