无法提取自定义HTTP请求标头

问题描述 投票:0回答:1

是否必须在我们要包含在http请求中的自定义标头中添加像http_ , x_ or header_这样的前缀?

我正在使用GetServerVariable API提取HTTP请求中发送的自定义Http标头的值,并且似乎没有提取并非以上述前缀开头的值。我使用Windows 10和IIS版本10。

任何提示?

http iis http-headers isapi custom-headers
1个回答
0
投票

您可以尝试使用以下代码从Web API请求中获取自定义标头的值;它扩展了HttpRequestMessage类:

假设您有一个HttpRequestMessage对象,则可以这样调用它:

var customHeaderValue = request.GetHeaderValue("Custom-Header");
© www.soinside.com 2019 - 2024. All rights reserved.