使用 Firefox 插件的 RESTClient 将数据发布到 REST API
我正在使用 RESTClient for firefox addon 来测试 REST API,我设置了一些标头,如果我将请求正文和方法设置为 GET ,则工作正常,我无法通过我的 PHP 应用程序访问数据,但标头可用
**Request headers**
Content-Type : application/json
**Request Body**
[
{
"data1" : "value1",
"data2" : "value2",
"data3" : 1
}
]
如何正确设置请求正文?
I am using RESTClient for firefox addon to test REST API, i set some headers that's working fine if i set request body and method to GET , i couldn't access data via my PHP application, but headers available
**Request headers**
Content-Type : application/json
**Request Body**
[
{
"data1" : "value1",
"data2" : "value2",
"data3" : 1
}
]
How do i set Request body correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将正文设置为 GET 请求是“废话”,因为 GET 意味着检索一些信息,而请求的正文用于发送数据。
正是从这个角度来看,网络服务器在大多数情况下忽略 GET 请求的正文,这可以解释为什么您无法获取数据来自您的 PHP 脚本。
如果您请求的目的是创建或更新资源,您应该考虑使用POST或PUT来休息吧。
这里已经有一个主题几乎有相同的问题:HTTP GET with request body
Set a body to GET requests is a "nonsense" because GET means retrieve some information and the body of a request is used to send data.
It is precisely from this point of view that web servers, most of the time, ignore the body of a GET request, which could explain why you can't get your data from your PHP script.
If the purpose of your request is to create or update a resource you should consider using a POST or PUT to be REST.
There is already a topic opened with almost the same question here : HTTP GET with request body