简体   繁体   中英

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. 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.

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. 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.

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

代替$ _POST检查$ HTTP_RAW_POST_DATA var

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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