【发布时间】:2017-07-16 11:37:50
【问题描述】:
我正在尝试使用 Web API 接收来自数据提供者的帖子。
当我使用以下函数从我的 web api 保存请求时:
public async Task<HttpResponseMessage> Import(HttpRequestMessage request)
然后将下面代码中的流保存到文件中:
var stream = await request.Content.ReadAsStreamAsync();
我得到以下结果:
--------------2226e2cc2af7d11c
内容配置:表单数据;名称="xml";文件名="test.xml.gz" 内容类型:application/octet-stream
[GZip 数据放在这里...]
--------------2226e2cc2af7d11c
内容配置:表单数据; name="myId1"
123
--------------2226e2cc2af7d11c
内容配置:表单数据; name="myId2"
456 --------------------------2226e2cc2af7d11c--
这当然不是正确的 GZip 格式。然后我尝试使用以下代码将请求作为多部分请求处理:
var streamContent = new StreamContent(stream);
streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream");
var provider = await streamContent.ReadAsMultipartAsync();
但是,然后出现下面的错误:
Invalid 'HttpContent' instance provided. It does not have a content type header starting with 'multipart/'
那么,我的问题是,如何从请求中的 xml 参数中获取 gzip 数据?我需要保存 gzip 数据,然后再解压缩并处理数据。
谢谢!
【问题讨论】:
标签: .net xml asp.net-web-api gzipstream