简体   繁体   English

PHP HTTP Post Server-无法获取发布请求

[英]PHP HTTP Post Server - can't get post requests

So I'm working on a group project for school, and we're working with a client who wants a companion app of sorts to go with his companies device. 因此,我正在为一个学校的小组项目工作,我们正在与一位希望与他的公司设备配合使用配套应用程序的客户一起工作。 We provide the device a host IP or domain and it sends HTTP Post requests in the form of XML every 5 seconds or so. 我们为设备提供主机IP或域,并且每5秒钟左右以XML形式发送HTTP Post请求。 The problem we're having is we have NO idea how to capture the data being sent on our server. 我们遇到的问题是我们不知道如何捕获服务器上发送的数据。 Simply trying to grab and dump all $_POST data yields an empty array, and our attempts to use a socket have produced similar results. 简单地尝试获取和转储所有$ _POST数据会产生一个空数组,而我们尝试使用套接字产生了相似的结果。

We've tried pointing the device to http://posttestserver.com/ - and it gets the data perfectly, though there is no source code available to see how the site operates. 我们尝试将设备指向http://posttestserver.com/-尽管没有可用的源代码来查看网站的运行方式,但它可以完美地获取数据。 Admittedly our knowledge of server side scripting is limited at best as we've only been working with PHP for a couple months, and this isn't something that has been covered. 诚然,我们对服务器端脚本的了解最多是有限的,因为我们仅使用PHP已有几个月的时间,而这还没有涉及到。

The above mentioned post server produces the following output ( with some omitted data for privacy ). 上面提到的发布服务器产生以下输出(出于隐私目的,省略了一些数据)。 Any help in reproducing this or simply assistance in getting the data on our server would be greatly appreciated! 非常感谢您提供任何有关复制此内容的帮助,或者只是协助获取我们服务器上的数据而已!

Time: Sun, 09 Nov 14 14:20:26 -0800
Source ip: ######

Headers (Some may be inserted by server)
HTTP_CONNECTION = close
REQUEST_URI = /post.php
QUERY_STRING = 
REQUEST_METHOD = POST
GATEWAY_INTERFACE = CGI/1.1
REMOTE_PORT = ######
REMOTE_ADDR = ######
CONTENT_LENGTH = 488
CONTENT_TYPE = application/xml
HTTP_USER_AGENT = Raven Uploader/v1
HTTP_FROM = ######
HTTP_ACCEPT = */*
HTTP_HOST = posttestserver.com
HTTPS = on
UNIQUE_ID = VF-oqtBx6hIAACKZ7j0AAAAH
REQUEST_TIME_FLOAT = 1415571626.7993
REQUEST_TIME = 1415571626

No Post Params.

== Begin post body ==
<?xml version="1.0"?><clientcompany macId="######" version="1.1" timestamp="1415571625s">
<PriceCluster>
  <DeviceMacId>######</DeviceMacId>
  <MeterMacId>######</MeterMacId>
  <TimeStamp>0x1bf2a52d</TimeStamp>
  <Price>0x00000467</Price>
  <Currency>0x007c</Currency>
  <TrailingDigits>0x04</TrailingDigits>
  <Tier>0x01</Tier>
  <StartTime>0x1bf2a52d</StartTime>
  <Duration>0xffff</Duration>
  <RateLabel>Block 2</RateLabel>
</PriceCluster>

</clientcompany>

== End post body ==

Upload contains PUT data:
<?xml version="1.0"?><clientcompany macId="0xd8d5b90016d1" version="1.1" timestamp="1415571625s">
<PriceCluster>
  <DeviceMacId>######</DeviceMacId>
  <MeterMacId>######</MeterMacId>
  <TimeStamp>0x1bf2a52d</TimeStamp>
  <Price>0x00000467</Price>
  <Currency>0x007c</Currency>
  <TrailingDigits>0x04</TrailingDigits>
  <Tier>0x01</Tier>
  <StartTime>0x1bf2a52d</StartTime>
  <Duration>0xffff</Duration>
  <RateLabel>Block 2</RateLabel>
</PriceCluster>

</clientcompany>

You need to capture the raw input stream: 您需要捕获原始输入流:

//$data = $_POST; <-- will be empty unless you are sending a key value pair(s)
$data = file_get_contents('php://input'); //<-- will capture all posted data
echo '== Begin post body ==';   
echo $data;
echo '== End post body ==';

If you need to see headers as well you can use getallheaders function: http://php.net/manual/en/function.getallheaders.php 如果还需要查看标题,则可以使用getallheaders函数: http : getallheaders

代替$ _POST检查$ HTTP_RAW_POST_DATA var

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM