本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}