什么是的WebAPI默认的HTTP动词? GET或POST? [英] What is the default HTTP verb in WebApi ? GET or POST?

查看:1093
本文介绍了什么是的WebAPI默认的HTTP动词? GET或POST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是珍玩。我在网上看的网络的项目之一。

Just curios. I was looking at one of the web projects at internet.

而code流程是这样的:

And the code flow is like this:

[RoutePrefix("/person")]
public class PersonController : ApiController
{

    //....
    [Route("/register")]
    public IHttpACtionResult RegisterPerson(PersonDto personDto)
    {
        //....
    }
    //....
}

你有没有注意到上面的code?没有 [HTTPGET()] [HttpPost()] 指定。然而,上述code失败了 GET 电话,但工作了 POST 电话。

Did you notice the above code? There is no [HttpGet()] or [HttpPost()] specified. Yet the above code fails for a GET call but works for a POST call.

任何想法,这种方法的HTTP动词是怎么解决的?

Any ideas how this method's HTTP-Verb is resolved ?

注:我知道,如果一个方法名与 GET POST ,然后相应的方法是通过调用启动 HTTPGET HTTPPost 。但该方法的名称在这里与注册开始...

Note: I know that if a methodname starts with GET or POST, then correspondingly the method is invoked via HTTPGet or HTTPPost. But the method name here starts with Register....

任何想法如何工作的吗?

Any ideas how this works?

推荐答案

由于你有你的方式(RegisterPerson)的参数(PersonDto)...它有后的东西,否则你将无法访问水合DTO对象。

Because you have an argument (PersonDto) for your method (RegisterPerson)...it has to "post" something, or you won't have access to a hydrated dto object.

虽然这是关于WCF,一个段落鸡舍有点light..especially上GET的自然

While this is about WCF, one paragraph sheds a little light..especially on the nature of GET

https://msdn.microsoft.com /en-us/library/bb628610(v=vs.110).aspx

ASP.NET AJAX支持使用HTTP POST和HTTP GET动词,使用HTTP POST作为默认操作。当创建一个没有任何副作用,并返回数据很少或从不改变的操作,使用HTTP GET来代替。 获取操作的结果可以被缓存,这意味着在同一操作的多个调用可能会导致只有一个要求为你服务。的高速缓存不是由WCF完成,但可以在任何一级进行(以用户的浏览器,代理服务器,以及其他的水平。)高速缓存是有利的,如果你想提高服务性能,但是,如果数据频繁改变或可以不被接受,如果该操作执行一些动作。

ASP.NET AJAX supports operations that use the HTTP POST and HTTP GET verbs, with HTTP POST being the default. When creating an operation that has no side effects and returns data that rarely or never changes, use HTTP GET instead. Results of GET operations can be cached, which means that multiple calls to the same operation may result in only one request to your service. The caching is not done by WCF but can take place at any level (in a user's browser, on a proxy server, and other levels.) Caching is advantageous if you want to increase service performance, but may not be acceptable if data changes frequently or if the operation performs some action.

这篇关于什么是的WebAPI默认的HTTP动词? GET或POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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