如何使用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');