Emulating HTTP POST using command line hangs and exporting output to a text file

How to emulate an HTTP POST request using curl and commit the result to a text file? I already have a script called dump.php:

<?php
  $var = print_r($GLOBALS, true);
  $fp = fopen('raw-post.txt','w');
  fputs($fp,$var);
  fclose($fp);
?>

I did a simple test by doing:

curl -d 'echo=hello' http://localhost/dump.php

but I did not see the data that I dumped into the output file. I expected it to appear in one of the POST arrays, but it is empty.

[_POST] => Array
    (
    )

[HTTP_POST_VARS] => Array
    (
    )
+3
source share
3 answers

You need to use $_GLOBALS, not $GLOBALS.

Alternatively, you can do this instead of using output buffering:

$var = print_r($_GLOBALS, true);

true print_r , . ​​

+2

(') :

curl -d hello=world -d test=yes http://localhost/dump.php
+1

If you're just trying to grab POST data, do something like this for you dump.php.

<?php
    $data = print_r($_POST, true);
    $fp = fopen('raw-post.txt','w');
    fwrite($fp, $data);
    fclose($fp);
?>

All POST data is stored in a variable $_POST. Also, if you need GET data, it $_REQUESTwill contain both.

0
source

All Articles