Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何在Web API中接收GZIP post请求?_.net_Xml_Asp.net Web Api_Gzipstream - Fatal编程技术网

.net 如何在Web API中接收GZIP post请求?

.net 如何在Web API中接收GZIP post请求?,.net,xml,asp.net-web-api,gzipstream,.net,Xml,Asp.net Web Api,Gzipstream,我正在尝试使用Web API接收来自数据提供商的帖子 当我使用下面的函数保存来自web api的请求时: public async Task<HttpResponseMessage> Import(HttpRequestMessage request) 我得到以下结果: --------------------------2226e2cc2af7d11c 内容配置:表单数据;name=“xml”;filename=“test.xml.gz” 内容类型:应用程序/八位字节流 [GZi

我正在尝试使用Web API接收来自数据提供商的帖子

当我使用下面的函数保存来自web api的请求时:

public async Task<HttpResponseMessage> Import(HttpRequestMessage request)
我得到以下结果:

--------------------------2226e2cc2af7d11c

内容配置:表单数据;name=“xml”;filename=“test.xml.gz” 内容类型:应用程序/八位字节流

[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数据,然后稍后解压并处理数据


谢谢

解决方案是创建一个定制的MultipartFormDataStreamProvider

我在本文中找到了一个解决方案:

Invalid 'HttpContent' instance provided. It does not have a content type header starting with 'multipart/'