HTTP:如何查看原始HTTP内容?

时间:2023-01-09 20:16:18

In particular, I am interested in viewing the 3 main types of data routinely sent to PHP, and available in the $_GET, $_POST and $_COOKIE arrays.

特别是,我有兴趣查看常规发送到PHP的3种主要数据类型,并且可以在$ _GET,$ _POST和$ _COOKIE数组中使用。

I’m not very conversant with HTTP, but as far as I am aware, the data sent from a form (method=post or get), a URL query string, or in cookies, is put into the HTTP headers and then sent to the server. (I’m not entirely sure whether that’s the case for method=post). It is, for the most part, in plain text.

我不太熟悉HTTP,但据我所知,从表单(method = post或get),URL查询字符串或cookie中发送的数据被放入HTTP头中,然后发送到服务器。 (我不完全确定method = post是否属于这种情况)。在大多数情况下,它是纯文本。

The question is, how can I view this HTTP content in its raw form?

问题是,如何以原始形式查看此HTTP内容?

I am interested mainly to get a better understanding of the process.

我感兴趣的主要是为了更好地了解这个过程。

3 个解决方案

#1


0  

The only piece of data that ends up in some PHP superglobal that's transmitted in HTTP headers are cookies. Such cookies often include the session ID used by sessions. $_GET gets populated from the URL:

在HTTP标头中传输的某些PHP超全局中唯一的数据是cookie。此类cookie通常包括会话使用的会话ID。从URL填充$ _GET:

An associative array of variables passed to the current script via the URL parameters

通过URL参数传递给当前脚本的关联变量数组

$_POST gets populated from the request body of HTTP request that use POST method, as long as they are formatted using one of the two formats implemented:

$ _POST从使用POST方法的HTTP请求的请求主体填充,只要它们使用实现的两种格式之一进行格式化:

An associative array of variables passed to the current script via the HTTP POST method when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request.

当使用application / x-www-form-urlencoded或multipart / form-data作为请求中的HTTP Content-Type时,通过HTTP POST方法传递给当前脚本的关联变量数组。

In both cases, you need to understand that they are convenience methods that work when you follow certain guidelines. Not all raw information is usable this way.

在这两种情况下,您都需要了解它们是遵循某些准则时可行的便捷方法。并非所有原始信息都可以这种方式使用。

As per the way to inspect raw data, all decent major browsers nowadays include developer tools with a Network pane. Such tools are often mapped to the F12 keyboard short-cut. In the PHP side, you can inspect part of the raw URL with var_dump($_SERVER['REQUEST_URI']) (this variable won't include the protocol prefix, host name or port) and you can inspect raw POST body with e.g. var_dump(file_get_contents("php://input")).

根据检查原始数据的方式,现在所有体面的主流浏览器都包含带有网络窗格的开发人员工具。这些工具通常映射到F12键盘快捷键。在PHP方面,您可以使用var_dump($ _ SERVER ['REQUEST_URI'])检查原始URL的一部分(此变量将不包括协议前缀,主机名或端口),您可以检查原始POST主体,例如:的var_dump(的file_get_contents( “PHP://输入”))。

#2


0  

You can try $requestBody = file_get_contents('php://input'); I think this can help you.

你可以尝试$ requestBody = file_get_contents('php:// input');我想这可以帮到你。

#3


0  

As all $_GET,$_POST and $_COOKIE are arrays you can aslo do print_r to view the content in raw form.

由于所有$ _GET,$ _ POST和$ _COOKIE都是数组,您可以执行print_r以原始形式查看内容。

print_r($_GET);
print_r($_POST);
print_r($_COOKIE);

#1


0  

The only piece of data that ends up in some PHP superglobal that's transmitted in HTTP headers are cookies. Such cookies often include the session ID used by sessions. $_GET gets populated from the URL:

在HTTP标头中传输的某些PHP超全局中唯一的数据是cookie。此类cookie通常包括会话使用的会话ID。从URL填充$ _GET:

An associative array of variables passed to the current script via the URL parameters

通过URL参数传递给当前脚本的关联变量数组

$_POST gets populated from the request body of HTTP request that use POST method, as long as they are formatted using one of the two formats implemented:

$ _POST从使用POST方法的HTTP请求的请求主体填充,只要它们使用实现的两种格式之一进行格式化:

An associative array of variables passed to the current script via the HTTP POST method when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request.

当使用application / x-www-form-urlencoded或multipart / form-data作为请求中的HTTP Content-Type时,通过HTTP POST方法传递给当前脚本的关联变量数组。

In both cases, you need to understand that they are convenience methods that work when you follow certain guidelines. Not all raw information is usable this way.

在这两种情况下,您都需要了解它们是遵循某些准则时可行的便捷方法。并非所有原始信息都可以这种方式使用。

As per the way to inspect raw data, all decent major browsers nowadays include developer tools with a Network pane. Such tools are often mapped to the F12 keyboard short-cut. In the PHP side, you can inspect part of the raw URL with var_dump($_SERVER['REQUEST_URI']) (this variable won't include the protocol prefix, host name or port) and you can inspect raw POST body with e.g. var_dump(file_get_contents("php://input")).

根据检查原始数据的方式,现在所有体面的主流浏览器都包含带有网络窗格的开发人员工具。这些工具通常映射到F12键盘快捷键。在PHP方面,您可以使用var_dump($ _ SERVER ['REQUEST_URI'])检查原始URL的一部分(此变量将不包括协议前缀,主机名或端口),您可以检查原始POST主体,例如:的var_dump(的file_get_contents( “PHP://输入”))。

#2


0  

You can try $requestBody = file_get_contents('php://input'); I think this can help you.

你可以尝试$ requestBody = file_get_contents('php:// input');我想这可以帮到你。

#3


0  

As all $_GET,$_POST and $_COOKIE are arrays you can aslo do print_r to view the content in raw form.

由于所有$ _GET,$ _ POST和$ _COOKIE都是数组,您可以执行print_r以原始形式查看内容。

print_r($_GET);
print_r($_POST);
print_r($_COOKIE);