$ _POST无法在Web服务中运行?

问题描述:

I am stuck from 2 days, I am working with web services and this web services is make request from iOS, They are send request with $_POST method but it is not working.

I tried to print_r($_POST) but its return blank Array() and also try with $_REQUEST but its return blank Array() only GET method work proper.

I also make <form> and try to submit with POST method and print both $_POST and $_REQUEST then both are work proper.

When print $_SERVER['REQUEST_METHOD'] then it return GET.

Please guys any one known how it happen ?

Here, I am able to find my answer and issue. For mod_rewrite is change request method. If you have a rewrite rule that affects the action URL, you will not able to read the POST variable.

You have to add this rule to .htaccess , at the beginning, to avoid to rewrite the url:

RewriteRule ^login.php - [PT]

Firstly, we would need to see your code to be able to help you fully. Below is a little example of how to use forms in combination with PHP and $_POST.

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    echo "<pre>";
    var_dump($_POST);
    echo "</pre>";
    exit;
}
?>

<!-- HTML -->
<form method="POST" action="<?= $_SERVER['PHP_SELF']; ?>">
    <input type="text" name="element" />
    <button type="submit">Submit form</button>
</form>