Postman request to PHP using POST

This is my code:

<?php
    if(isset($_POST["test"]))
        echo $_POST["test"];
    if(isset($_GET["test"]))
        echo $_GET["test"];
?>

My question is: why POST request doesn't work?

I have tried different parameters in the body and the header and nothing works.

GET request in Postman works: GET request Postman

POST request in Postman fails: POST request Postman

Upvotes: 1

Views: 19573

Answers (4)

talfie
talfie

Reputation: 11

Your request might be redirected:

  • All of your requests are sent as GET requests, no matter which HTTP request method you select.
  • The original HTTP request method you selected is not preserved when there is a redirect between HTTP and HTTPS."

https://support.postman.com/hc/en-us/articles/211913929-My-request-is-redirected-to-a-GET-request

Upvotes: 1

Tobias Dimoji
Tobias Dimoji

Reputation: 21

  1. In the header tab, set "Content-Type"-"application/x-www-form-urlencoded"

  2. In the body tab, choose form-data

  3. Enter your key/value pairs. These represent the name parameter in your PHP or HTML form and their expected values

  4. Change request type to POST and enter the url of the script that will process the form. This is the full url of the action parameter in your form

Upvotes: 2

Menura Adithya
Menura Adithya

Reputation: 41

First of all you have to set the headers as "Content-Type"-"application/x-www-form-urlencoded" and disable "Content-Type"-"application/json".

After that in the body tab select "x-www-form-urlencoded" field not the "raw" field and enter the values you need to post as the post request.

Don't forget to change the request type to POST.

Upvotes: 3

Ragupathi
Ragupathi

Reputation: 599

<?php 
  $name = $_POST['name'];
  echo $name;
?>

Upvotes: 9

Related Questions