简体   繁体   English

使用POST方法调用REST api会调用GET方法

[英]Invoking REST api using POST method invokes GET method

I am developing a firefox plugin which invokes a rest api using post method. 我正在开发一个firefox插件,它使用post方法调用rest api。 The rest api will persist the data if it is invoked using POST. 如果使用POST调用数据,其余的api将保留数据。 If it is invoked using GET method, it will retrieve the data persisted previously. 如果使用GET方法调用它,它将检索先前持久化的数据。

But in some cases, the api returns the persisted data even though it is invoked using the POST data. 但在某些情况下,api会返回持久化数据,即使它是使用POST数据调用的。

I am under confusion whether the way I send the data is wrong or whether there is something wrong with api. 我发送数据的方式是错误还是api有问题,我感到很困惑。 But most of the requests gets served correctly. 但大多数请求都得到了正确的服务。 So, I don't think that there is something wrong with plugin. 所以,我认为插件没有问题。 Te back end is on ROR. Te后端是ROR。

Any help will be great! 任何帮助都会很棒!

Thanks. 谢谢。

It's not uncommon for RESTful services to return a copy of the (updated) data in response to a POST. RESTful服务返回(更新的)数据的副本以响应POST并不罕见。

All you really care about is that it's updating the remote data when you POST. 您真正关心的是它在POST时更新远程数据。 Whether or not it returns a copy of that data is something you may be able to safely ignore. 无论它是否返回该数据的副本,您都可以安全地忽略它。

If it's intermittent, one possibility is that there is an HTTP cache in between your server and client which is poorly implemented, and doesn't differentiate properly between the GET and POST methods. 如果它是间歇性的,一种可能性是服务器和客户端之间存在HTTP缓存,实现不当,并且无法在GET和POST方法之间正确区分。 Perhaps it is attempting to return a cached copy as if you had made a GET request even though you sent a POST request. 也许它正在尝试返回一个缓存副本,就好像你发出了一个GET请求,即使你发送了一个POST请求。

If instead "in some cases" means "for some URL's", then it's possible that you are POST'ing to a URL like "/foo" (no trailing slash) and the service returns 301 or 302, redirecting the client to "/foo/" (with a trailing slash). 如果相反“在某些情况下”意味着“对于某些URL”,那么您可能会POST到像“/ foo”这样的URL(没有尾部斜杠),并且服务返回301或302,将客户端重定向到“/ foo /“(带斜杠)。 Most user-agents will change the POST to a GET for 302, and some will for 301. If you have control over the server, you should use 303 or 307 instead. 大多数用户代理将POST更改为GET为302,有些将为301.如果您可以控制服务器,则应使用303或307。 See http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-16#section-8.3.3 http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-16#section-8.3.3

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

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