How to test php api in postman? json_decode(file_get_contents('php://input'), true);
I want to test my Php api in postman, please guide me,
Below code working fine and this php api code using for Android Retrofit but i want to test this api in postman.
<?php
require 'db.php';
$data = json_decode(file_get_contents('php://input'), true);
if($data['mobile'] == '' or $data['password'] == '')
{
$returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went Wrong!");
}
else
{
$mobile = strip_tags(mysqli_real_escape_string($con,$data['mobile']));
$password = strip_tags(mysqli_real_escape_string($con,$data['password']));
$chek = $con->query("select * from user where (mobile='".$mobile."' or email='".$mobile."') and status = 1 and password='".$password."'");
$status = $con->query("select * from user where status = 1");
if($status->num_rows !=0)
{
if($chek->num_rows != 0)
{
$c = $con->query("select * from user where (mobile='".$mobile."' or email='".$mobile."') and status = 1 and password='".$password."'");
$c = $c->fetch_assoc();
$returnArr = array("ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Login successfully!");
}
else
{
$returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Invalid Email/Mobile No or Password!!!");
}
}
else
{
$returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Your Status Deactivate!!!");
}
}
echo json_encode($returnArr);
Thanks in advance :)
Answer
Solution:
In postmane first create new request.
Then select POST as request and insert your localhost URL ( eg. http://localhost/project_folder_name/YOUR_FILE_NAME.php )
In below tab select Body.
In Body select raw to pass request data.
Pass below json
{ "mobile":"asdsad", "password":"asdasd" }
- click send button you will get result
Atteached screen shot of postman request.
List item
Source