简体   繁体   English

如何从 HttpListenerResponse .NET 核心获取所有标头

[英]How to get all headers from HttpListenerResponse .NET core

I have a HttpListenerResponse which Headers array only contains 2 entries.我有一个 HttpListenerResponse,其中 Headers 数组仅包含 2 个条目。 The entire content of the HttpListenerResponse is seen in this picture HttpListenerResponse 的全部内容见这张图

在此处输入图像描述

I'm testing my HttpListener by using Postman.我正在使用 Postman 测试我的 HttpListener。 In my postman Response I see the following headers:在我的 postman 响应中,我看到以下标题: 在此处输入图像描述

As you can see the Server and Date headers are present in the response but not in my HttpListenerResponse content.如您所见,响应中存在 Server 和 Date 标头,但我的 HttpListenerResponse 内容中没有。 Why are they not there and how can I get them?为什么他们不在那里,我怎样才能得到他们?

Im not a.Net expert, but when i tried to create an API Gateway i had the same problem.我不是 .Net 专家,但是当我尝试创建 API 网关时,我遇到了同样的问题。 For me, to be able to access all the headers in Net Core, i had to use the interface IHeaderDictionary of Microsoft.AspNetCore.Http package.对我来说,为了能够访问 Net Core 中的所有标题,我必须使用 Microsoft.AspNetCore.Http package 的接口 IHeaderDictionary。 The headers will be a property of HttpContext.Request object.标头将是 HttpContext.Request object 的属性。

返回所有标头的 API 网关控制器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在.NET中将www-authenticate标头添加到HttpListenerResponse - How to add www-authenticate header to HttpListenerResponse in .NET 如何从.NET中的WebBrowser控件获取响应头? - How to get response headers from WebBrowser control in .NET? 使用 .NET Core 2.2 从 Azure 存储中获取所有 Blob - Get all Blobs From Azure Storage using .NET Core 2.2 添加AllowAnyHeader不允许.NET Core 3.1中的所有标头 - Adding AllowAnyHeader does not allow all headers in .NET Core 3.1 如何在.NET Core中获取defaultNamingContext? - How to get the defaultNamingContext in .NET Core? 如何从 .Net Core 中的 Content.ReadAsStringAsync 方法获取字符串? - How to get the string from Content.ReadAsStringAsync method in .Net Core? 如果扩展名未知,如何从文件中读取 (GET) - .NET Core 6 API - How To Read (GET) from File if Extension is Unknown - .NET Core 6 API 如何从外部网站获取数据到.NET Core中的Web API? - How to get data from external website into a web API in .NET core? 如何从 C# 网核中的数据库获取数据 - How to get data from DB in C# net core .NET Core 2 Shibboleth身份验证中间件,使用标头 - .NET Core 2 Shibboleth Authentication Middleware Using Headers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM