HttpClient不返回Content-Type [英] HttpClient does not return Content-Type

查看:206
本文介绍了HttpClient不返回Content-Type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 HttpClient 发送请求。服务器返回两个标头,我想返回给客户端。我是这样运行的:

I'm sending a request with HttpClient. Server returns two headers which I want return to client. I run it like this:

 using (var client = new HttpClient())
 {
     var response = await client.GetAsync(DownloadUri + $"?path={path}&fileName={fileName}");
     // ...
 }

但是在客户端,我有10个标头,而服务器发送12。
这是我在调试器中获得的 response.Headers.ToString()

But on client side I have 10 headers, while server sends 12. This is what I get in debugger for response.Headers.ToString():

Transfer-Encoding: chunked
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcQWxleFxEb2N1bWVudHNcdGZzXFVDRktcdnNuXGRldlxMYW5pdC5VQ0ZLLkZpbGUuU2VydmVyXEZpbGUuc3ZjXERvd25sb2Fk?=
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Credentials: true
Cache-Control: private
Date: Mon, 06 Jun 2016 12:19:09 GMT
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

这是我通过外部Rest客户获得的:

And this is what I get with external Rest client:

Content-Type Content-Dispos位置丢失。
如何使用 HttpClient 来获得它?

Content-Type and Content-Disposition are missing. How can I get it with HttpClient?

推荐答案

您应该查看 response.Content.Headers ,您应该在此处找到与内容相关的标题。可以在下面的msdn链接上找到有关所有内容标头类型的更多信息。

You should look at response.Content.Headers you should find headers relating to the content here. More information about all the content header types can be found on the msdn link below.

https://msdn.microsoft.com/zh-cn/library/system.net.http。 headers.httpcontentheaders(v = vs.118).aspx

这篇关于HttpClient不返回Content-Type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆