如何使用PHP捕获完整的HTTP请求数据(标题和正文)? [英] How to capture full HTTP request data (headers and body) with PHP?

查看:112
本文介绍了如何使用PHP捕获完整的HTTP请求数据(标题和正文)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须实现一个与Java工作,但失败,卷曲工作的API的一个问题。我们已经通过到目前为止一切都过去了,就必须有一些是Java使什么我们做的要求是不同的。

I have a problem implementing an API that works with Java, but fails to work with cURL. We've gone through everything so far and there must be something that is different between the requests that Java makes and what we make.

在PHP中,我们可以通过查看 $获得头数据_ SERVER ['HTTP _ *] 变量,我们可以从的file_get_contents得到请求体( PHP://输入'); 但是,我们不能从用户代理发送到客户端的确切数据。

In PHP we can get header data by looking at $_SERVER['HTTP_*'] variables and we can get request body from file_get_contents('php://input'); But we cannot get the exact data sent from user agent to client.

时有可能得到完整的请求,该用户代理发送,用PHP?标题和正文包括在内?如果是这样,那么如何?

Is it possible to get the full request, that user agent sends, with PHP? Headers and body included? If so, then how?

我发现的唯一的例子是的这里,但是这一次得到的身体我提到的方法,同时通过 $ _ SERVER ,这似乎是一个黑客解析得到头因为它从来没有什么实际发送100%。

The only example I found is here, but this one gets the body the way I mentioned, while it gets headers by parsing through $_SERVER, which seems like a hack since it's never 100% of what was actually sent.

所有帮助和提示AP preciated!

All help and tips are appreciated!

推荐答案

有关的头,你可以尝试的 apache_request_headers()和身体我不知道比的file_get_contents('PHP://输入');

for headers you can try apache_request_headers() and for body I dont know other method than file_get_contents('php://input');

这篇关于如何使用PHP捕获完整的HTTP请求数据(标题和正文)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆