c#HTTP Multipart MIME解析器

时间:2013-06-10 15:39:12

标签: c# mime multipart

我从HTTP调用中获取Multipart MIME响应,需要提取部件。我正在寻找一种简单的方法来做到这一点。

我正在使用System.Net.Http方法来获取内容,但是提取响应部分让我感到困惑。

HttpClient zClient = new HttpClient();
Uri zAddress = new Uri("http://someDomain.com");

HttpContent content = new StringContent(sb.ToString());
HttpResponseMessage response = zClient.PostAsync(zAddress, content).Result;
if (response.IsSuccessStatusCode)
{
    // This returns true
    bool zIsMime = response.Content.IsMimeMultipartContent();

    // How do I get the message parts here. This ReadAsMultipartAsync method is confusing me. 
    ReadAsMultipartAsync(HttpContent) ???? 

}
else
{
    Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}

1 个答案:

答案 0 :(得分:1)

MultipartMemoryStreamProvider zMIME = await response.Content.ReadAsMultipartAsync();

这是我正在寻找的简单步骤。