简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM