当前位置: 首页>>代码示例>>C#>>正文


C# StringContent.ReadAsAsync方法代码示例

本文整理汇总了C#中System.Net.Http.StringContent.ReadAsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StringContent.ReadAsAsync方法的具体用法?C# StringContent.ReadAsAsync怎么用?C# StringContent.ReadAsAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.StringContent的用法示例。


在下文中一共展示了StringContent.ReadAsAsync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadAsAsyncOfT_WhenTypeIsReferenceTypeAndNoMediaType_ReturnsNull

        public void ReadAsAsyncOfT_WhenTypeIsReferenceTypeAndNoMediaType_ReturnsNull()
        {
            var content = new StringContent("{}");
            content.Headers.ContentType = null;
            var formatters = new MediaTypeFormatter[] { new JsonMediaTypeFormatter() };

            Assert.Equal(null, content.ReadAsAsync<List<string>>(formatters).Result);
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:8,代码来源:HttpContentExtensionsTest.cs

示例2: ReadAsAsyncOfT_WhenNoMatchingFormatterFoundForContentWithNoMediaType_Throws

        public void ReadAsAsyncOfT_WhenNoMatchingFormatterFoundForContentWithNoMediaType_Throws()
        {
            var content = new StringContent("{}");
            content.Headers.ContentType = null;
            var formatters = new MediaTypeFormatter[] { new JsonMediaTypeFormatter() };

            Assert.Throws<InvalidOperationException>(() => content.ReadAsAsync<List<string>>(formatters),
                "No MediaTypeFormatter is available to read an object of type 'List`1' from content with media type ''undefined''.");
        }
开发者ID:sanyaade-mobiledev,项目名称:aspnetwebstack-1,代码行数:9,代码来源:HttpContentExtensionsTest.cs

示例3: ReadAsAsyncOfT_WhenTypeIsReferenceTypeAndNoMediaType_Throws

        public void ReadAsAsyncOfT_WhenTypeIsReferenceTypeAndNoMediaType_Throws()
        {
            var content = new StringContent("{}");
            content.Headers.ContentType = null;
            var formatters = new MediaTypeFormatter[] { new JsonMediaTypeFormatter() };

            Assert.Throws<UnsupportedMediaTypeException>(() => content.ReadAsAsync<List<string>>(formatters),
                "No MediaTypeFormatter is available to read an object of type 'List`1' from content with media type 'application/octet-stream'.");
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:9,代码来源:HttpContentExtensionsTest.cs

示例4: ReadAsAsyncOfT_WhenNoMatchingFormatterFound_Throws

        public void ReadAsAsyncOfT_WhenNoMatchingFormatterFound_Throws()
        {
            var content = new StringContent("{}");
            content.Headers.ContentType = _mediaType;
            content.Headers.ContentType.CharSet = "utf-16";
            var formatters = new MediaTypeFormatter[] { new JsonMediaTypeFormatter() };

            Assert.Throws<InvalidOperationException>(() => content.ReadAsAsync<List<string>>(formatters),
                "No MediaTypeFormatter is available to read an object of type 'List`1' from content with media type 'foo/bar'.");
        }
开发者ID:sanyaade-mobiledev,项目名称:aspnetwebstack-1,代码行数:10,代码来源:HttpContentExtensionsTest.cs

示例5: ReadingFormData

        public static void ReadingFormData()
        {
            var content = new StringContent("a[]=1&a[]=5&a[]=333", Encoding.UTF8, "application/x-www-form-urlencoded");

            //  var body = await content.ReadAsFormDataAsync();
            var body = content.ReadAsAsync<JObject>().Result;
            
            // Verify that the data we read was the same as we submitted to the `StringContent`.
            var arr = (JArray)body["a"];
            Helpers.AssertEquality(Helpers.__, arr.ToString()); 
        }
开发者ID:sara62,项目名称:WebApiKoans,代码行数:11,代码来源:AboutContent.cs

示例6: ReadAsAsyncOfT_InvokesFormatterEvenIfContentLengthIsZero

        public void ReadAsAsyncOfT_InvokesFormatterEvenIfContentLengthIsZero()
        {
            var content = new StringContent("");
            _formatterMock.Setup(f => f.CanReadType(typeof(string))).Returns(true);
            _formatterMock.Object.SupportedMediaTypes.Add(content.Headers.ContentType);

            var result = content.ReadAsAsync<string>(_formatters);

            result.WaitUntilCompleted();
            _formatterMock.Verify(f => f.ReadFromStreamAsync(typeof(string), It.IsAny<Stream>(), content.Headers, It.IsAny<IFormatterLogger>()), Times.Once());
        }
开发者ID:sanyaade-mobiledev,项目名称:aspnetwebstack-1,代码行数:11,代码来源:HttpContentExtensionsTest.cs

示例7: ReadAsAsyncOfT_WhenTypeIsValueTypeAndNoMediaType_ReturnsDefault

        public void ReadAsAsyncOfT_WhenTypeIsValueTypeAndNoMediaType_ReturnsDefault()
        {
            var content = new StringContent("123456");
            content.Headers.ContentType = null;
            var formatters = new MediaTypeFormatter[] { new JsonMediaTypeFormatter() };

            Assert.Equal(0, content.ReadAsAsync<int>(formatters).Result);
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:8,代码来源:HttpContentExtensionsTest.cs

示例8: ReadAsAsyncOfT_cancellationToken_PassesCancellationTokenFurther

        public void ReadAsAsyncOfT_cancellationToken_PassesCancellationTokenFurther()
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            cts.Cancel();
            HttpContent content = new StringContent("42", Encoding.Default, "application/json");

            Assert.Throws<TaskCanceledException>(() => content.ReadAsAsync<int>(cts.Token).Wait());
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:8,代码来源:HttpContentExtensionsTest.cs


注:本文中的System.Net.Http.StringContent.ReadAsAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。