如何禁用http响应中的所有标头内容。 [英] How to disable all the header content from http response.

查看:448
本文介绍了如何禁用http响应中的所有标头内容。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

how to disable the sending of http header data in api response.

like fallowing headers in asp.net web api 2

Cache-Control →no-cache
Connection →close
Content-Length →20
Content-Type →application/json; charset=utf-8
Date →Mon, 12 Jun 2017 10:06:04 GMT
Expires →-1
Pragma →no-cache
Server →Microsoft-IIS/8.5
X-AspNet-Version →4.0.30319





我尝试过:



i尝试在global.asax中添加休假代码



What I have tried:

i have tried adding fallowing code in global.asax

protected void Application_PreSendRequestHeaders()
       {
           Response.Headers.Remove("Server");
           Response.Headers.Remove("X-AspNet-Version");
           Response.Headers.Remove("Expires");
           Response.Headers.Remove("Cache-Control");
           Response.Headers.Remove("Connection");
           Response.Headers.Remove("Date");
           Response.Headers.Remove("Content-Type");


       }





和iis http响应标题我删除了X使用以上程序支付


我可以禁用



and from iis http response header i have removed X powered by

with above procedure i am able to disable

Server

X-AspNet-Version

X powered by

标题提供支持

我无法删除剩余的标题

headers but
I am unable to delete remaining header those are

Cache-Control →no-cache
Content-Length →7
Content-Type →application/json; charset=utf-8
Date →Sun, 25 Jun 2017 12:15:41 GMT
Expires →-1
Pragma →no-cache

。即使我有尝试使用uriscan工具。

任何帮助都可以使用。

.Even i Have tried with uriscan tool also.
Any help could be appreicated.

推荐答案

简单:你没有。



这些标头是HTTP语法的一部分。如果你删除它们,你的回复将不再有效。



超文本传输​​协议 - 维基百科 [ ^ ]

HTTP标题字段列表 - 维基百科 [ ^ ]



您可以更改 Cache-Control Expires Pragma 通过设置 CacheControl [ ^ ]属性回复。



响应格式化程序将设置 Content-Type Content-Length 标头。它们无法更改或删除,因为这会破坏响应。



日期会自动设置,并且无法更改或删除。
Simple: You don't.

Those headers are part of the HTTP grammar. If you removed them, your response would no longer be valid.

Hypertext Transfer Protocol - Wikipedia[^]
List of HTTP header fields - Wikipedia[^]

You can change the Cache-Control, Expires and Pragma headers by setting the CacheControl[^] property on the response.

The Content-Type and Content-Length headers will be set by the response formatter. They cannot be changed or removed, since that would break the response.

The Date is set automatically, and cannot be changed or removed.


这篇关于如何禁用http响应中的所有标头内容。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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