Good morning,
i am going to be receiving data via HTTP POST from a vendor and will need to be able to parse out the data. The format of the data is proprietary/unknown to me at the moment and may change as we are both coding at the same time. I cannot initiate the sending of data without calling and having someone there make it happen which would be very time consuming during the development and testing of my code.
I thought it would be simple to just have them send me a snippet of the stream periodically and build a simple form into which i could paste the snippet and have it sent to my code but apparently i'm missing something.
I need to be able to get the whole post so i have been trying to use php://input but everything i try just results in the browser timing out. I have tried several examples that i have found online but they all result in a timeout. I read somewhere that the content-length needs to be set so i've tried doing that to no avail. I have also read that this may be a bug in PHP. i am running 5.0.27-community-nt. Should i be upgrading?
Here are a couple of my attempts. It's a bit messy as i'm flailing but hopefully it is clear enough. Can someone please give me a bit of direction?
thanks,
dean
ATTEMPT #1
<?php
function firstRun()
{
if (!isset($_POST['submit']))
return true;
}
function secondRun()
{
//$data = file_get_contents('php://input');
$fp = fopen('php://input','r');
while (!feof($fp))
echo fgets($fp);
fclose($fp);
print $data;
print "see it:<br />";
print $_POST['dataSnippet'];
print strlen($_POST['dataSnippet']);
print $HTTP_RAW_POST_DATA;
}
function snippetForm()
{
?>
<form id="datasnippet" method="post" action="terminal_DataPost.php" content-type="UTF197/TCS" content-length="4">
<table align="center">
<tr>
<td>
Data Snippet:
</td>
</tr>
<tr>
<td>
<textarea cols="25" rows="3" name="dataSnippet"></textarea>
</td>
<tr>
<td></td>
<td>
<input type="hidden" name="submit" value="1" />
<input type="submit" name="submitButton" value="Submit" />
</td>
</tr>
</table> </form><br />
<?php
}
?>
ATTEMPT #2
<form action="index2.php" method="post">
<p>
<label for="text">Zone de texte :</label>
<input type="text" name="text" id="text" />
</p>
<p><input type="submit" name="submit" value="Continuer" /></p>
</form>
<p><?php echo file_get_contents('php://input'); ?></p>
ATTEMPT #3
<form action="index1.php" method="post">
<input type="text" value="demo" />
<input type="submit" />
</form>
<?php
$fp = fopen('php://input','r');
while (!feof($fp))
echo fgets($fp);
fclose($fp);
print $_POST['text'];
?>