Reputation: 97
I maintain a webshop that generates xml files of it's orders. These orders should be pushes to a URL of the fulfilment center using http-POST.
We build a script for this and tested it ones against the URL of the fulfilment center and it appears to work, but since we can't keep testing against that URL (as the FFC would think that it are real orders) I want to make my own test envoirement. Were I can dump the content sent with POST to one .xml per order again.
For this I tried several scripts including Dump XML Posts from 'php://input' to file, but none of them seem to work. Dumping to TXT would also be fine for testing purposes.
Does any of you have an idea what I can do?
Upvotes: 1
Views: 840
Reputation: 97
Solution with thanks to SO-UserVic Degraeve.
$input = file_get_contents("php://input");
$xml = urldecode($input);
$fh = fopen(time() . ".xml", 'a') or die ("Can't create file!");
fwrite($fh, $xml);
fclose($fh);
Upvotes: 0
Reputation: 973
you can use an extension for your browser for firefox, HTTP Resource Test
I've misunderstood the question
you can also do this, which imo is more simple it will append the content to a txt file
function debug($content){
$fh = fopen("postrequest.txt", 'a') or die("can't open file");
fwrite($fh, $content."\n");
fclose($fh);
}
$input = file_get_contents("php://input");
debug($input);
Upvotes: 2
Reputation: 8838
Try this simple array to xml conversion if $_POST having single dimension array.
$post_arr = $_POST;
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($post_arr , array ($xml, 'addChild'));
print $xml->asXML();
For multi-dimensional array: Refer this SO Answer:
https://stackoverflow.com/a/19051521/270037
Upvotes: 1
Reputation: 4506
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($_POST, array ($xml, 'addChild'));
print $xml->asXML();
Upvotes: 1