本文整理汇总了C#中RequestMessage.SetEncodingFilter方法的典型用法代码示例。如果您正苦于以下问题:C# RequestMessage.SetEncodingFilter方法的具体用法?C# RequestMessage.SetEncodingFilter怎么用?C# RequestMessage.SetEncodingFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestMessage
的用法示例。
在下文中一共展示了RequestMessage.SetEncodingFilter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolvedServiceReadRequestMissingEncoding
public void ResolvedServiceReadRequestMissingEncoding()
{
ServiceCollection services = new ServiceCollection();
services
.WithHostFormat(new JsonFormat())
.WithService("Test", "/")
.WithEndpoint("{action}")
.Post<Payload>((Payload p) => { });
byte[] encodedPayload;
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("{\"date\":\"2012-09-22T18:46:00Z\",\"number\":42,\"text\":\"Hello, world!\"}")))
{
using (MemoryStream outputStream = new MemoryStream())
{
using (GZipStream compressionStream = new GZipStream(outputStream, CompressionMode.Compress))
{
stream.CopyTo(compressionStream);
}
encodedPayload = outputStream.ToArray();
}
}
ResolvedService service = new ServiceResolver(services).Find(MethodType.Post, "foo");
using (RequestMessage request = new RequestMessage<Payload>(service.Name, service.RouteValues, new Uri("http://example.com/foo")))
{
request.InputStream.Write(encodedPayload, 0, encodedPayload.Length);
request.InputStream.Position = 0;
request.SetEncodingFilter(EncodingType.Parse("gzip"), new GzipDeflateEncoding());
ReadRequestResult result = service.ReadRequest(request, encodedPayload.Length, "gzip", "application/json", request.InputStream);
Assert.IsNotNull(result);
Assert.IsFalse(result.Success);
Assert.IsNull(result.Exception);
Assert.AreEqual(StatusCode.UnsupportedMediaType, result.StatusCode);
Assert.IsNull(result.RequestObject);
}
}