简体   繁体   English

使用 file_get_contents 的 Rest POST API 在 PHP 中不起作用

[英]Rest POST API With file_get_contents Not Working IN PHP

i am writing new php post api how to get output.我正在编写新的 php post api 如何获取输出。

URL : http://localhost/webservices/test.php网址: 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 请求时,我可以处理。

JSON Example Request : JSON 示例请求:

{"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 http://localhost/webservices/test.php?firstName=Ram&lastName=R

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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