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


C# ByteArrayContent.ReadAsMultipartAsync方法代码示例

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


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

示例1: ReadAsMultipartAsync_NestedMultipartContent

        public void ReadAsMultipartAsync_NestedMultipartContent(string boundary)
        {
            const int nesting = 10;
            const string innerText = "Content";

            MultipartContent innerContent = new MultipartContent("mixed", boundary);
            innerContent.Add(new StringContent(innerText));
            for (var cnt = 0; cnt < nesting; cnt++)
            {
                string outerBoundary = String.Format("{0}_{1}", boundary, cnt);
                MultipartContent outerContent = new MultipartContent("mixed", outerBoundary);
                outerContent.Add(innerContent);
                innerContent = outerContent;
            }

            MemoryStream memStream = new MemoryStream();
            innerContent.CopyToAsync(memStream).Wait();
            memStream.Position = 0;
            byte[] data = memStream.ToArray();
            HttpContent content = new ByteArrayContent(data);
            content.Headers.ContentType = innerContent.Headers.ContentType;

            for (var cnt = 0; cnt < nesting + 1; cnt++)
            {
                MultipartMemoryStreamProvider result = content.ReadAsMultipartAsync().Result;
                Assert.Equal(1, result.Contents.Count);
                content = result.Contents[0];
                Assert.NotNull(content);
            }

            string text = content.ReadAsStringAsync().Result;
            Assert.Equal(innerText, text);
        }
开发者ID:RhysC,项目名称:aspnetwebstack,代码行数:33,代码来源:HttpContentMultipartExtensionsTests.cs

示例2: ReadAsMultipartAsyncNestedMultipartContentAsync

        public void ReadAsMultipartAsyncNestedMultipartContentAsync(string boundary)
        {
            const int nesting = 10;
            const string innerText = "Content";

            MultipartContent innerContent = new MultipartContent("mixed", boundary);
            innerContent.Add(new StringContent(innerText));
            for (var cnt = 0; cnt < nesting; cnt++)
            {
                string outerBoundary = String.Format("{0}_{1}", boundary, cnt);
                MultipartContent outerContent = new MultipartContent("mixed", outerBoundary);
                outerContent.Add(innerContent);
                innerContent = outerContent;
            }

            MemoryStream memStream = new MemoryStream();
            innerContent.CopyToAsync(memStream).Wait();
            memStream.Position = 0;
            byte[] data = memStream.ToArray();
            HttpContent content = new ByteArrayContent(data);
            content.Headers.ContentType = innerContent.Headers.ContentType;

            for (var cnt = 0; cnt < nesting + 1; cnt++)
            {
                Task<IEnumerable<HttpContent>> task = content.ReadAsMultipartAsync();
                task.Wait(TimeoutConstant.DefaultTimeout);
                IEnumerable<HttpContent> result = task.Result;
                Assert.Equal(1, result.Count());
                content = result.ElementAt(0);
                Assert.NotNull(content);
            }

            string text = content.ReadAsStringAsync().Result;
            Assert.Equal(innerText, text);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:35,代码来源:HttpContentMultipartExtensionsTests.cs

示例3: ReadAsMultipartAsync_UsingMultipartContent

        public void ReadAsMultipartAsync_UsingMultipartContent(string boundary)
        {
            MultipartContent content = new MultipartContent("mixed", boundary);
            content.Add(new StringContent("A"));
            content.Add(new StringContent("B"));
            content.Add(new StringContent("C"));

            MemoryStream memStream = new MemoryStream();
            content.CopyToAsync(memStream).Wait();
            memStream.Position = 0;
            byte[] data = memStream.ToArray();
            var byteContent = new ByteArrayContent(data);
            byteContent.Headers.ContentType = content.Headers.ContentType;

            MultipartMemoryStreamProvider result = byteContent.ReadAsMultipartAsync().Result;
            Assert.Equal(3, result.Contents.Count);
            Assert.Equal("A", result.Contents[0].ReadAsStringAsync().Result);
            Assert.Equal("B", result.Contents[1].ReadAsStringAsync().Result);
            Assert.Equal("C", result.Contents[2].ReadAsStringAsync().Result);
        }
开发者ID:RhysC,项目名称:aspnetwebstack,代码行数:20,代码来源:HttpContentMultipartExtensionsTests.cs

示例4: ReadAsMultipartAsyncUsingMultipartContentAsync

        public void ReadAsMultipartAsyncUsingMultipartContentAsync(string boundary)
        {
            MultipartContent content = new MultipartContent("mixed", boundary);
            content.Add(new StringContent("A"));
            content.Add(new StringContent("B"));
            content.Add(new StringContent("C"));

            MemoryStream memStream = new MemoryStream();
            content.CopyToAsync(memStream).Wait();
            memStream.Position = 0;
            byte[] data = memStream.ToArray();
            var byteContent = new ByteArrayContent(data);
            byteContent.Headers.ContentType = content.Headers.ContentType;

            Task<IEnumerable<HttpContent>> task = byteContent.ReadAsMultipartAsync();
            task.Wait(TimeoutConstant.DefaultTimeout);
            IEnumerable<HttpContent> result = task.Result;
            Assert.Equal(3, result.Count());
            Assert.Equal("A", result.ElementAt(0).ReadAsStringAsync().Result);
            Assert.Equal("B", result.ElementAt(1).ReadAsStringAsync().Result);
            Assert.Equal("C", result.ElementAt(2).ReadAsStringAsync().Result);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:22,代码来源:HttpContentMultipartExtensionsTests.cs


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