Magnil Amar
Magnil Amar

Reputation: 84

Rest POST API With file_get_contents Not Working IN PHP

i am writing new php post api how to get output.

URL : http://localhost/webservices/test.php

currently i am using postman for development purpose.when i get request as json i am able to handle.

JSON Example Request :

{"firstName":"Ram","lastName" :"R"}

$request  = file_get_contents('php://input');
$parameters = json_decode($request,true);

$firstName = $parameters['firstName'];
echo $firstName ; // output will be Ram

Now My Question is how can i get reponse from Request Like This

firstName=Ram&lastName=R

Now how can Get First Name ?

Thanks in advance.

Upvotes: 1

Views: 446

Answers (1)

Gopal Palraj
Gopal Palraj

Reputation: 58

You can Use following Method to get Values from Header.

$fname   = $_GET['firstName'];
echo $fname;

your Url will be like:

http://localhost/webservices/test.php?firstName=Ram&lastName=R

Upvotes: 1

Related Questions