如何检查file_get_contents是否有POST?

Hi I need to check if file_get_contents posts data to the server.. my script look like this

<?php
$foo = file_get_contents("http://www.example.com");

if ($_SERVER[REQUEST_METHOD] == POST)
{
// do action
}

echo $foo;
?>

I know that file_get_contents stops my script, any help is appreciated

A simple file_get_contents call never sends POST data to the server - just a a simple GET request. So you dont have anything in your $_POST var.

Exceptions:

  • The other server add some POST data on their own.
  • You pass an context to file_get_contents, which changes the request to a POST request