.NET的WebAPI HTTPGET VS HttpPost。为什么HTTPGET? [英] .net webapi HttpGet vs HttpPost. why HttpGet?

查看:298
本文介绍了.NET的WebAPI HTTPGET VS HttpPost。为什么HTTPGET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在框架的WebAPI HTTPGET使用,而不是HttpPost?

Why use HttpGet instead of HttpPost in the WebApi framework?

据我了解还有一个帖子的区别或优惠类型,一种是通过URL和其他没有(如基本的了解)

I understand well the difference between a Post or Get type, one is via url and the other not (as basic understanding)

但也知道委托人差(其可以是在服务器上编辑)是发布不具有数据尺寸的任何限制其发送到服务器,而在GET类型具有的限制

But also I know the principal difference (which can be edit on the server) is that Post doesn't have any limitation in the data size send it to the server, while the GET type has a limitation of

(2000个字符(IE的上限)。)
   HTTP GET URI额度

(2000 characters (IE's limit.)) HTTP URI GET limit

当我被编码大量有时我感到沮丧发送数据是在通过GET极限数据大小的数据,发现服务器发送错误和误差修改,是因为大小,所以我不得不改变我赞成方法的 POST 键入

When I been coding large amount of data sometime I been frustrated to send data which is over the limit data size via GET and found the server sending error and erros and is because the size, so I have to change my methods in favor of POST type.

namespace somenamespace.Controllers
{
    public class someController : ApiController
    {
        [HttpPost] //<--- change all
        public somenamespace.Class getSomething(string key1, string key2) {
            return new someblabla.Models.Class.Class(key1,key2).getSomething();
        }
    }
}

那么,为什么会是一个很好的理由当有人想用GET而不是POST,而POST总是与任何限制工作的。

So why would be a GOOD reason when someone want to use GET instead of POST, while POST is always working with any restriction at all.

我说的是只有约WEB API .NET。我知道,如果你想通过URL字符串来请求变量和信息(节点,经逐页)或类似的GET可以更容易实现。

I'm talking about only about WEB API .net. I know if you want to request variables and information via an url string (sending vía page to page) or something like that GET can be more easy to implement.

推荐答案

最后你总是可以做任何你想要的,但它是很好的做法,遵循一定的标准 - 不只是标准的缘故,而是为了让自己code predictable和易于使用。

Ultimately you can always do whatever you want but it's good practice to follow some standards - not just for the standard's sake but to make your code predictable and easy to use.

当你打电话给你的RESTful API的人会认为,例如:

When you call your API RESTful people will assume that, e.g.:


  • 任何GET请求将刚刚得到的数据 - 不能修改,不能删除,不能创建

  • any GET request will just get the data - not modify, not delete, not create

任何POST请求将创建资源

any POST request will create a resource

PUT请求将更新的资源,并根据需要无副作用,可以执行他们多次

PUT requests will update resources, and you can execute them as many times as you want without side effects

删除的意志,那么,删除该资源

DELETE will, well, delete the resource

这让大家的生活更轻松,是那种你和客户之间的合同。

That makes everyone's life easier and is sort of a contract between you and your customers.

我强烈建议你读的API REST风格的设计,这种资源 - 你会得到什么原因人们对以下公约的理念是:

I highly recommend that you read this resource on RESTful design of APIs - you'll get the idea what reasons people have for following a convention:

http://info.apigee.com/Portals/62317/文档/网页%20api.pdf

这篇关于.NET的WebAPI HTTPGET VS HttpPost。为什么HTTPGET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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