$_POST 方法中的 URL PUSH 问题

发布于 2024-12-20 06:52:08 字数 303 浏览 3 评论 0原文

目前我一直在开发一个连接到短信网关的项目。一旦用户向网关发送短信,它就会将请求重定向到我们的服务器。问题是它们是通过 $_GET 方法接收的。但短信提供商表示他们正在 $_POST 方法中传递它。我们最后收到的 URL 如下所示。

http://www.example.com/smstest?msg=sample&id=55788

使用$_POST方法是否可以接收url中的参数

Currently i have been working on a project which connects to a smsgateway. Once the user sends sms to gateway it redirects the requests to our server. Problem is they are received in $_GET method. But the sms provider says they are passing it in $_POST method. Url received at our end looks like the following.

http://www.example.com/smstest?msg=sample&id=55788

Is it possible to receive parameters in url when you use the $_POST method

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

你另情深 2024-12-27 06:52:08

HTTP 请求可以使用 HTTP 方法 POST 并且仍然使用包含查询参数的 URL。 POST 只是 HTTP 标头中使用的“动词”,与 GET 相同(以及 PUTDELETE )。 URL 始终可以包含查询参数,也可以始终包含请求正文(尽管 GET 请求不应该)。 PHP 变量 $_GET 仅表示已解析的 URL 查询参数,变量 $_POST 仅表示已解析的请求正文。它们实际上与 HTTP 动词没有任何关系,因此有些命名错误。

An HTTP request can use the HTTP method POST and still use a URL that contains query parameters. POST is just a "verb" used in the HTTP header, the same as GET (and PUT and DELETE). A URL can always contain query parameters and it can also always contain a request body (though GET requests shouldn't). The PHP variable $_GET simply represents the parsed URL query parameters, the variable $_POST simply represents the parsed request body. They do not actually have anything to do with the HTTP verb and are therefore somewhat misnamed.

云雾 2024-12-27 06:52:08

是的。每个 HTTP 请求的第一行包含 方法(或动词)和发出请求的 URI。根据方法的选择,对 URI 没有特殊限制,因此可以对包含

在 PHP 中,您通常可以通过 $_GET$_REQUEST 访问查询字符串中的参数。作为提交表单的一部分传递的参数一如既往地可以通过 $_POST$_REQUEST 访问。

Yes, it is. The first line of every HTTP request contains the method (or verb) and the URI for which the request is made. No special restrictions are placed on the URI based on the choice of method, so POST requests may be made for a URI that includes a query string.

From PHP you can access the parameters in the query string normally through $_GET and $_REQUEST. Parameters passed as part of a submitted form are accessible as always through $_POST and $_REQUEST.

月亮是我掰弯的 2024-12-27 06:52:08

只能有一个动词 (POST, GET, PUT, ...) 执行HTTP 请求时。但是,您可以这样做

<form name="y" method="post" action"y.php?foo=bar">

,然后 PHP 也会填充 $_GET['foo'],尽管请求是 POST 的。

发表评论

通过使用

$_SERVER['REQUEST_METHOD']

You can only have one verb (POST, GET, PUT, ...) when doing an HTTP Request. However, you can do

<form name="y" method="post" action"y.php?foo=bar">

and then PHP will populate $_GET['foo'] as well, although the Request was POST'ed.

For comment

By using

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