简体   繁体   English

HttpMethod和HttpRequest的RequestType有什么区别?

[英]What's the difference between HttpMethod and RequestType of HttpRequest?

The HttpRequest class defines two properties: HttpRequest类定义了两个属性:

HttpMethod : HttpMethod

Gets the HTTP data transfer method (such as GET, POST, or HEAD) used by the client. 获取客户端使用的HTTP数据传输方法(如GET,POST或HEAD)。

 public string HttpMethod { get; } 

The HTTP data transfer method used by the client. 客户端使用的HTTP数据传输方法。

and RequestType : RequestType

Gets or sets the HTTP data transfer method (GET or POST) used by the client. 获取或设置客户端使用的HTTP数据传输方法(GET或POST)。

 public string RequestType { get; set; } 

A string representing the HTTP invocation type sent by the client. 表示客户端发送的HTTP调用类型的字符串。

What is the difference between these two properties? 这两个属性有什么区别? When would I want to use one over the other? 我什么时候想要使用另一个? Which is the proper one to inspect to see what data transfer method was used by the client? 哪个是检查以查看客户端使用的数据传输方法的正确方法?

The documentation indicates that HttpMethod will return whatever verb was used: 文档表明HttpMethod将返回使用的动词:

such as GET, POST, or HEAD 例如GET,POST或HEAD

while the documentation on RequestType seems to indicate only one of two possible values: RequestType上的文档似乎只表示两个可能值中的一个:

GET or POST GET或POST


I tested with a random sampling of verbs, and both properties seem to support all verbs, and both return the same values: 我使用动词的随机抽样进行测试,这两个属性似乎都支持所有动词,并且都返回相同的值:

Testing: 测试:

Client Used    HttpMethod    RequestType
GET            GET           GET
POST           POST          POST
HEAD           HEAD          HEAD
CONNECT        CONNECT       CONNECT
MKCOL          MKCOL         MKCOL
PUT            PUT           PUT
FOOTEST        FOOTEST       FOOTEST

What is the difference between: 有什么区别:

  • HttpRequest.HttpMethod HttpRequest.HttpMethod
  • HttpRequest.RequestType HttpRequest.RequestType

and when should I use one over the other? 什么时候应该使用另一个?

Reflector shows that RequestType calls HttpMethod internally. Reflector显示RequestType内部调用HttpMethod So you're ever so slightly better off calling HttpMethod . 所以你打电话给HttpMethod好一点 Actually I think the real reason RequestType exists was for backwards compatibility with classic ASP. 实际上我认为RequestType存在的真正原因是为了向后兼容经典ASP。

You can check below article:- 您可以查看以下文章: -

Request methods: An HTTP request made using telnet. 请求方法:使用telnet发出的HTTP请求。 The request, response headers and response body are highlighted. 请求,响应标头和响应正文将突出显示。

HTTP defines eight methods (sometimes referred to as "verbs") indicating the desired action to be performed on the identified resource. HTTP定义了八种方法(有时称为“动词”),指示要对所识别的资源执行的所需操作。 What this resource represents, whether pre-existing data or data that is generated dynamically, depends on the implementation of the server. 此资源表示的是,预先存在的数据还是动态生成的数据,取决于服务器的实现。 Often, the resource corresponds to a file or the output of an executable residing on the server. 通常,资源对应于驻留在服务器上的文件或可执行文件的输出。

HEAD Asks for the response identical to the one that would correspond to a GET request, but without the response body. HEAD要求响应与对应于GET请求的响应相同,但没有响应主体。 This is useful for retrieving meta-information written in response headers, without having to transport the entire content. 这对于检索在响应头中编写的元信息非常有用,而无需传输整个内容。

GET Requests a representation of the specified resource. GET请求指定资源的表示。 Note that GET should not be used for operations that cause side-effects, such as using it for taking actions in web applications. 请注意,GET不应用于导致副作用的操作,例如使用它在Web应用程序中执行操作。 One reason for this is that GET may be used arbitrarily by robots or crawlers, which should not need to consider the side effects that a request should cause. 其中一个原因是机器人或爬虫可以任意使用GET,这不应该考虑请求应该引起的副作用。 See safe methods below. 请参阅以下安全方法。

POST Submits data to be processed (eg, from an HTML form) to the identified resource. POST将要处理的数据(例如,从HTML表单)提交到标识的资源。 The data is included in the body of the request. 数据包含在请求正文中。 This may result in the creation of a new resource or the updates of existing resources or both. 这可能导致创建新资源或更新现有资源或两者。 PUT Uploads a representation of the specified resource. PUT上载指定资源的表示。 DELETE Deletes the specified resource. DELETE删除指定的资源。 TRACE Echoes back the received request, so that a client can see what intermediate servers are adding or changing in the request. TRACE回显收到的请求,以便客户端可以查看在请求中添加或更改的中间服务器。 OPTIONS Returns the HTTP methods that the server supports for specified URL. 选项返回服务器支持指定URL的HTTP方法。 This can be used to check the functionality of a web server by requesting '*' instead of a specific resource. 这可以通过请求'*'而不是特定资源来检查Web服务器的功能。 CONNECT Converts the request connection to a transparent TCP/IP tunnel, usually to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy.[5] CONNECT将请求连接转换为透明的TCP / IP隧道,通常是为了通过未加密的HTTP代理来促进SSL加密通信(HTTPS)。[5] PATCH Is used to apply partial modifications to a resource.[6] PATCH用于对资源进行部分修改。[6]

HTTP servers are required to implement at least the GET and HEAD methods[7] and, whenever possible, also the OPTIONS method.[citation needed] Safe methods HTTP服务器至少需要实现GET和HEAD方法[7],并且尽可能实现OPTIONS方法。[引证需要]安全方法

Some methods (for example, HEAD, GET, OPTIONS and TRACE) are defined as safe, which means they are intended only for information retrieval and should not change the state of the server. 某些方法(例如,HEAD,GET,OPTIONS和TRACE)被定义为安全,这意味着它们仅用于信息检索,不应更改服务器的状态。 In other words, they should not have side effects, beyond relatively harmless effects such as logging, caching, the serving of banner advertisements or incrementing a web counter. 换句话说,它们不应该具有副作用,除了相对无害的效果,例如日志记录,缓存,横幅广告的提供或递增网络计数器。 Making arbitrary GET requests without regard to the context of the application's state should therefore be considered safe. 因此,在不考虑应用程序状态的上下文的情况下进行任意GET请求应该被认为是安全的。

By contrast, methods such as POST, PUT and DELETE are intended for actions which may cause side effects either on the server, or external side effects such as financial transactions or transmission of email. 相比之下,POST,PUT和DELETE等方法适用于可能导致服务器副作用或外部副作用(如金融交易或电子邮件传输)的操作。 Such methods are therefore not usually used by conforming web robots or web crawlers, which tend to make requests without regard to context or consequences. 因此,这些方法通常不适用于符合网络机器人或网络爬行器,这些机器人倾向于在不考虑背景或后果的情况下提出请求。

Despite the prescribed safety of GET requests, in practice their handling by the server is not technically limited in any way, and careless or deliberate programming can just as easily (or more easily, due to lack of user agent precautions) cause non-trivial changes on the server. 尽管GET请求具有规定的安全性,但实际上它们对服务器的处理在技术上并没有任何限制,粗心或故意的编程可以很容易(或者更容易,由于缺乏用户代理预防措施)导致非平凡的变化在服务器上。 This is discouraged, because it can cause problems for Web caching, search engines and other automated agents, which can make unintended changes on the server. 不鼓励这样做,因为它可能会导致Web缓存,搜索引擎和其他自动代理出现问题,这些代理可能会对服务器进行意外更改。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM