-4

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 ?

Mayank Vadiya
  • 1,437
  • 2
  • 19
  • 32
  • 2
    No code? No solution... Can you share some relevant code? ;) – Koen Hollander Oct 24 '16 at 08:04
  • 1
    How do you expect anyone to help if you don't post your code in the question? Is this meant to be a _guessing game_? – arkascha Oct 24 '16 at 08:07
  • From your description you are not sending the request via POST or you are doing something wrong when sending the request which makes it go via GET. PHP will not inexplicably change an incoming POST request to GET. – apokryfos Oct 24 '16 at 08:08
  • I am using web services they this web service is send request from iOS device. I am just print `$_POST` and it will return blank – Mayank Vadiya Oct 24 '16 at 08:09
  • @apokryfos , I am send request from POSTMAN with POST method. – Mayank Vadiya Oct 24 '16 at 08:10
  • So you are saying that it leaves POSTMAN as POST but arrives at PHP as GET? – apokryfos Oct 24 '16 at 08:13
  • yes @apokryfos , thanks bro to understand – Mayank Vadiya Oct 24 '16 at 08:13
  • Can you share your request header here? – apokryfos Oct 24 '16 at 08:19
  • @apokryfos Cache-Control →max-age=172800 Connection →keep-alive Content-Encoding →gzip Content-Length →70 Content-Type →text/html Date →Mon, 24 Oct 2016 06:28:00 GMT Expires →Wed, 26 Oct 2016 06:28:00 GMT Keep-Alive →timeout=5, max=100 Server →Apache Vary →Accept-Encoding,User-Agent Via →HTTP/1.1 sophos.http.proxy:3128 – Mayank Vadiya Oct 24 '16 at 08:21
  • Just edit your question with the raw request. It's impossible to understand it as a comment. Also that looks like the response header. – apokryfos Oct 24 '16 at 08:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/126504/discussion-between-mayank-vadiya-and-apokryfos). – Mayank Vadiya Oct 24 '16 at 09:22

2 Answers2

1

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]

Mayank Vadiya
  • 1,437
  • 2
  • 19
  • 32
0

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>
Peter
  • 8,776
  • 6
  • 62
  • 95