php get raw get data
PHP: Receive raw POST data.
This is a short guide on how to receive raw POST data in PHP. This is useful if you intend on receiving JSON or XML via a POST request.
In most day-to-day cases, we tend to access POST data like so:
However, in certain cases, you may need to access the POST request’s body as a whole. In those cases, you will need to access the php://input stream.
The php://input stream.
PHP has a number of I/O streams that you can access. In this case, we are particularly interested in the php://input stream.
Take a look at the following example:
In the code above, we used the file_get_contents function to read the php://input stream into a PHP variable called $postBody.
If a POST request is sent to the script above, the entire body of the request will be assigned to the $postBody variable.
For example: When I sent three POST parameters to the script in question, the php://input stream returned the following string:
Note that if no POST data is present, the code above will return a blank string.
$HTTP_RAW_POST_DATA is a predefined PHP variable that can be configured to contain raw POST data. However, the variable was officially deprecated in PHP 5.6 and completely removed as of PHP 7.0.
Besides the fact that it is no longer supported, there is also the drawback of having to mess around with .ini directives in order to get it working. This is because the feature is turned off by default on most PHP installations.
The feature relies on the always_populate_raw_post_data directive being set to 1. However, the default value for this directive is 0 (off).
Long story short: You should use the input stream approach instead.
Я ищу точное определение этого, но все еще не могу найти определение удовлетворения.
Я использовал nusoap webservice, есть строка
Решение
HTTP-запрос состоит из двух частей. Набор заголовков и тела.
Заголовки включают в себя такие вещи, как запрашиваемый URL-адрес и кэширующие помощники управления (например, «У меня есть версия со вчерашнего дня, дайте мне новую, только если есть изменения, хорошо?»).
Тело может появиться или не появиться в зависимости от типа запроса. У запросов POST есть тела.
Тело может быть в любом формате, который нравится клиенту. Один из заголовков сообщит серверу, что это за формат.
Если данные представлены в другом формате, например, JSON, или если данные не соответствуют особенностям PHP (например, правила наличия [] на конце ключей с тем же именем), возможно, вы захотите получить доступ к данным непосредственно, так что вы можете разобрать его самостоятельно. Это необработанные данные POST.
$_POST содержит URL-кодированные (application / www-url-кодированные) переменные, которые публикуются в вашем скрипте, а PHP декодирует их для вас. Вы используете его, когда имеете дело с данными HTML FORM.
$HTTP_RAW_POST_DATA — в теории это то же самое, что и выше, но зависит от php.ini. и больше не доступен в PHP 7
Другие решения
HTTP-сообщение состоит из серии заголовков и тела (которое может быть обязательным / необязательным / запрещенным в зависимости от заголовков).
Если вы сделаете запрос GET для него, то тело запроса не будет.
Если вы сделаете запрос POST, то будет. Если вы отправите форму, она будет закодирована с использованием одного из форматов, которые вы можете указать с помощью enctype приписывать.
Сырое тело это тело до это было расшифровано.
magnetikonline / dumprequest.php
GET /dumprequest.php HTTP/1.1 |
HTTP headers: |
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 |
Accept-Encoding: gzip, deflate, br |
Referer: http://localhost/ |
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 |
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36 |
Upgrade-Insecure-Requests: 1 |
Connection: keep-alive |
Host: localhost |
Request body: |
This comment has been minimized.
Copy link Quote reply
beebopfr commented Oct 10, 2017
This comment has been minimized.
Copy link Quote reply
magnetikonline commented Oct 20, 2017
@beebopfr Request body of course 👍 Thanks!
This comment has been minimized.
Copy link Quote reply
chetanmadaan commented Dec 1, 2017
It’s a very useful script would be useful if it can dump
$_GET
data as well and also list
$_SERVER[‘REMOTE_ADDR’]
This comment has been minimized.
Copy link Quote reply
ToLive commented Dec 4, 2017
Nice script, thank you!
This comment has been minimized.
Copy link Quote reply
justinDevel commented Feb 15, 2018
This comment has been minimized.
Copy link Quote reply
Kobily commented Feb 22, 2018 •
This comment has been minimized.
Copy link Quote reply
mustafaredsignal commented May 1, 2018
Use this line to get GET/POST data
This comment has been minimized.
Copy link Quote reply
unionor commented May 14, 2018 •
add this line at the end to create a file for each request with timestamp
This comment has been minimized.
Copy link Quote reply
codebeat-nl commented Jul 28, 2018
This doesn’t need to be a class, could be a easy to use library function.
This comment has been minimized.
Copy link Quote reply
aago79 commented Nov 23, 2018
Hey! thanks for this script.
I’m a complete newbie and maybe I can not even explain myself. However what I need is to save data coming from an http request to my server on a file. Thus it seems that the above script is perfect for my needs.
What I do not understand is where to put the script and how let it works: should I put the script on my server and use is URL in the http request to let him works and create the file?
This comment has been minimized.
Copy link Quote reply
jotham commented Mar 7, 2019 •
For the next time I come across this- Single function version.