本文整理汇总了C#中Nancy.Response.Contents方法的典型用法代码示例。如果您正苦于以下问题:C# Response.Contents方法的具体用法?C# Response.Contents怎么用?C# Response.Contents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.Response
的用法示例。
在下文中一共展示了Response.Contents方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadResponseContent
private string ReadResponseContent(Response response)
{
string content;
using (var stream = new MemoryStream())
{
response.Contents(stream);
stream.Position = 0;
using (var reader = new StreamReader(stream))
{
content = reader.ReadToEnd();
}
}
return content;
}
示例2: ResponseSummary
public ResponseSummary(Response response)
{
_contentType = response.ContentType;
_headers = response.Headers;
_statusCode = response.StatusCode;
using (var memoryStream = new MemoryStream())
{
response.Contents(memoryStream);
_contents = memoryStream.ToArray();
}
}
示例3: SendNancyResponseToResult
static void SendNancyResponseToResult(Response response, ResultDelegate result)
{
if (!response.Headers.ContainsKey("Content-Type") && !string.IsNullOrWhiteSpace(response.ContentType))
response.Headers["Content-Type"] = response.ContentType;
result(
string.Format("{0:000} UNK", (int) response.StatusCode),
response.Headers,
(next, error, complete) =>
{
using (var stream = new OutputStream(next, complete))
{
try
{
response.Contents(stream);
}
catch (Exception ex)
{
error(ex);
}
}
return () => { };
});
}
示例4: MapNancyResponse
private HttpResponseMessage MapNancyResponse(Response src)
{
var dst = new HttpResponseMessage((HttpStatusCode)src.StatusCode);
if (src.Contents != null)
{
using (var memStream = new MemoryStream())
{
src.Contents(memStream);
dst.Content = new ByteArrayContent(memStream.ToArray());
}
foreach (var header in src.Headers)
{
if (contentHeaders.Contains(header.Key))
dst.Content.Headers.Add(header.Key, header.Value);
}
if (src.ContentType != null)
dst.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(src.ContentType);
}
foreach (var header in src.Headers.Where(x => !contentHeaders.Contains(x.Key)))
dst.Headers.Add(header.Key, header.Value);
return dst;
}