asp.net – ASP MVC – 默认的HTTP标头有任何常量吗?

基本上,同样的问题我要求认的内容类型,但这次为标题:有微软创建了一个类的标准HTTP头名称的常量,或者我必须自己写?

谢谢卢克

解决方法

请求标题
/// <summary>
/// Contains the standard set of headers applicable to an HTTP request.
/// </summary>
public static class HttpRequestHeaders
{
    ///<summary>Content-Types that are acceptable</summary>
    public const string Accept = "Accept";
    ///<summary>Character sets that are acceptable</summary>
    public const string AcceptCharset = "Accept-Charset";
    ///<summary>Acceptable encodings. SeeHTTP compression.</summary>
    public const string AcceptEncoding = "Accept-Encoding";
    ///<summary>Acceptable languages for response</summary>
    public const string AcceptLanguage = "Accept-Language";
    ///<summary>Acceptable version in time</summary>
    public const string AcceptDatetime = "Accept-Datetime";
    ///<summary>Authentication credentials for HTTP authentication</summary>
    public const string Authorization = "Authorization";
    ///<summary>Used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain</summary>
    public const string CacheControl = "Cache-Control";
    ///<summary>What type of connection the user-agent would prefer</summary>
    public const string Connection = "Connection";
    ///<summary>an HTTP cookie prevIoUsly sent by the server withSet-Cookie(below)</summary>
    public const string Cookie = "Cookie";
    ///<summary>The length of the request body inoctets(8-bit bytes)</summary>
    public const string ContentLength = "Content-Length";
    ///<summary>ABase64-encoded binaryMD5sum of the content of the request body</summary>
    public const string ContentMD5 = "Content-MD5";
    ///<summary>TheMIME typeof the body of the request (used with POST and PUT requests)</summary>
    public const string ContentType = "Content-Type";
    ///<summary>The date and time that the message was sent</summary>
    public const string Date = "Date";
    ///<summary>Indicates that particular server behaviors are required by the client</summary>
    public const string Expect = "Expect";
    ///<summary>The email address of the user making the request</summary>
    public const string From = "From";
    ///<summary>The domain name of the server (forvirtual hosting),mandatory since HTTP/1.1. Although domain name are specified as case-insensitive[5][6],it is not specified whether the contents of the Host field should be interpreted in a case-insensitive manner[7]and in practice some implementations of virtual hosting interpret the contents of the Host field in a case-sensitive manner.[citation needed]</summary>
    public const string Host = "Host";
    ///<summary>Only perform the action if the client supplied entity matches the same entity on the server. This is mainly for methods like PUT to only update a resource if it has not been modified since the user last updated it.</summary>
    public const string IfMatch = "If-Match";
    ///<summary>Allows a304 Not Modifiedto be returned if content is unchanged</summary>
    public const string IfModifiedSince = "If-Modified-Since";
    ///<summary>Allows a304 Not Modifiedto be returned if content is unchanged,seeHTTP ETag</summary>
    public const string IfNoneMatch = "if-none-match";
    ///<summary>If the entity is unchanged,send me the part(s) that I am missing; otherwise,send me the entire new entity</summary>
    public const string IfRange = "If-Range";
    ///<summary>Only send the response if the entity has not been modified since a specific time.</summary>
    public const string IfUnmodifiedSince = "If-Unmodified-Since";
    ///<summary>Limit the number of times the message can be forwarded through proxies or gateways.</summary>
    public const string MaxForwards = "Max-Forwards";
    ///<summary>Implementation-specific headers that may have varIoUs effects anywhere along the request-response chain.</summary>
    public const string Pragma = "Pragma";
    ///<summary>Authorization credentials for connecting to a proxy.</summary>
    public const string ProxyAuthorization = "Proxy-Authorization";
    ///<summary>Request only part of an entity. Bytes are numbered from 0.</summary>
    public const string Range = "Range";
    ///<summary>This is the address of the prevIoUs web page from which a link to the currently requested page was followed. (The word “referrer” is misspelled in the RFC as well as in most implementations.)</summary>
    public const string Referersic = "Referer[sic]";
    ///<summary>The transfer encodings the user agent is willing to accept: the same values as for the response header transfer-encoding can be used,plus the trailers value (related to the chunked transfer method) to notify the server it expects to receive additional headers (the trailers) after the last,zero-sized,chunk.</summary>
    public const string TE = "TE";
    ///<summary>Ask the server to upgrade to another protocol.</summary>
    public const string Upgrade = "Upgrade";
    ///<summary>Theuser agent stringof the user agent</summary>
    public const string UserAgent = "User-Agent";
    ///<summary>Informs the server of proxies through which the request was sent.</summary>
    public const string Via = "Via";
    ///<summary>A general warning about possible problems with the entity body.</summary>
    public const string Warning = "Warning";

}

回应标题

/// <summary>
/// Contains the standard set of headers applicable to an HTTP response.
/// </summary>
public static class HttpResponseHeaders
{
    ///<summary>What partial content range types this server supports</summary>
    public const string AcceptRanges = "Accept-Ranges";
    ///<summary>The age the object has been in aproxy cachein seconds</summary>
    public const string Age = "Age";
    ///<summary>Valid actions for a specified resource. To be used for a405 Method not allowed</summary>
    public const string Allow = "Allow";
    ///<summary>Tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds</summary>
    public const string CacheControl = "Cache-Control";
    ///<summary>Options that are desired for the connection[17]</summary>
    public const string Connection = "Connection";
    ///<summary>The type of encoding used on the data. SeeHTTP compression.</summary>
    public const string ContentEncoding = "content-encoding";
    ///<summary>The language the content is in</summary>
    public const string ContentLanguage = "Content-Language";
    ///<summary>The length of the response body inoctets(8-bit bytes)</summary>
    public const string ContentLength = "Content-Length";
    ///<summary>An alternate location for the returned data</summary>
    public const string ContentLocation = "Content-Location";
    ///<summary>ABase64-encoded binaryMD5sum of the content of the response</summary>
    public const string ContentMD5 = "Content-MD5";
    ///<summary>An opportunity to raise a File Download dialogue Box for a kNown MIME type with binary format or suggest a filename for dynamic content. Quotes are necessary with special characters.</summary>
    public const string Contentdisposition = "Content-disposition";
    ///<summary>Where in a full body message this partial message belongs</summary>
    public const string ContentRange = "Content-Range";
    ///<summary>TheMIME typeof this content</summary>
    public const string ContentType = "Content-Type";
    ///<summary>The date and time that the message was sent</summary>
    public const string Date = "Date";
    ///<summary>An identifier for a specific version of a resource,often amessage digest</summary>
    public const string ETag = "ETag";
    ///<summary>Gives the date/time after which the response is considered stale</summary>
    public const string Expires = "Expires";
    ///<summary>The last modified date for the requested object,inRFC 2822format</summary>
    public const string LastModified = "Last-Modified";
    ///<summary>Used to express a typed relationship with another resource,where the relation type is defined byRFC 5988</summary>
    public const string Link = "Link";
    ///<summary>Used in redirection,or when a new resource has been created.</summary>
    public const string Location = "Location";
    ///<summary>This header is supposed to setP3Ppolicy,in the form ofP3P:CP=your_compact_policy. However,P3P did not take off,[22]most browsers have never fully implemented it,a lot of websites set this header with fake policy text,that was enough to fool browsers the existence of P3P policy and grant permissions forthird party cookies.</summary>
    public const string P3P = "P3P";
    ///<summary>Implementation-specific headers that may have varIoUs effects anywhere along the request-response chain.</summary>
    public const string Pragma = "Pragma";
    ///<summary>Request authentication to access the proxy.</summary>
    public const string ProxyAuthenticate = "Proxy-Authenticate";
    ///<summary>Used in redirection,or when a new resource has been created. This refresh redirects after 5 seconds. This is a proprietary,non-standard header extension introduced by netscape and supported by most web browsers.</summary>
    public const string Refresh = "Refresh";
    ///<summary>If an entity is temporarily unavailable,this instructs the client to try again after a specified period of time (seconds).</summary>
    public const string RetryAfter = "Retry-After";
    ///<summary>A name for the server</summary>
    public const string Server = "Server";
    ///<summary>anHTTP cookie</summary>
    public const string SetCookie = "Set-Cookie";
    ///<summary>A HSTS Policy informing the HTTP client how long to cache the HTTPS only policy and whether this applies to subdomains.</summary>
    public const string StrictTransportSecurity = "Strict-Transport-Security";
    ///<summary>The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded withchunked transfer-coding.</summary>
    public const string Trailer = "Trailer";
    ///<summary>The form of encoding used to safely transfer the entity to the user.Currently defined methodsare:chunked,compress,deflate,gzip,identity.</summary>
    public const string TransferEncoding = "transfer-encoding";
    ///<summary>Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server.</summary>
    public const string vary = "vary";
    ///<summary>Informs the client of proxies through which the response was sent.</summary>
    public const string Via = "Via";
    ///<summary>A general warning about possible problems with the entity body.</summary>
    public const string Warning = "Warning";
    ///<summary>Indicates the authentication scheme that should be used to access the requested entity.</summary>
    public const string WWWAuthenticate = "WWW-Authenticate";

}

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....