當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。