Post方法在Web服务中不起作用

I'm running a simple file just to test methods are working properly in webservices. while running the file with Get method it is working fine but Postmethod is not working . Below is my code

    <?php
if($_SERVER['REQUEST_METHOD']== "POST"){

 $abc=$_POST['name'];

   echo $abc;
}
else{
    echo "method not accepted";
}

header('Content-type:application/json');
?>

while running the code it automatically goes to else part .How can i get this resolve .If anybody can suggest will be appreciated.

This should work perfectly. I believe, you are not making a POST request. Suggestion: If you are making the call from a form add

method="POST" in form tag

If you are making an ajax call $.ajax({ url:"url", type:"POST", data:"data" }).done();

Tip: You can't make a post call,by simply hitting the url from browser. You have to use POSTMAN to make POST calls manually.

You should never use == to compare strings. Use === or strcmp to compare 2 strings.