使用 Firefox 插件的 RESTClient 将数据发布到 REST API

发布于 2024-12-26 07:50:31 字数 326 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

予囚 2025-01-02 07:50:31

将正文设置为 GET 请求是“废话”,因为 GET 意味着检索一些信息,而请求的正文用于发送数据。

正是从这个角度来看,网络服务器在大多数情况下忽略 GET 请求的正文,这可以解释为什么您无法获取数据来自您的 PHP 脚本。

如果您请求的目的是创建更新资源,您应该考虑使用POSTPUT来休息吧。

这里已经有一个主题几乎有相同的问题: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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文