Post方法在webservices中不起作用

时间:2022-09-01 15:21:39

I'm running a simple file just to test methods are working properly in webservices. while running the file with Get method it is working fine but Postmethod is not working . Below is my code

我正在运行一个简单的文件,只是为了测试方法在webservices中是否正常工作。使用Get方法运行文件时它工作正常,但Postmethod不工作。以下是我的代码

    <?php
if($_SERVER['REQUEST_METHOD']== "POST"){

 $abc=$_POST['name'];

   echo $abc;
}
else{
    echo "method not accepted";
}

header('Content-type:application/json');
?>

while running the code it automatically goes to else part .How can i get this resolve .If anybody can suggest will be appreciated.

在运行代码时,它会自动转到其他部分。我怎样才能得到这个解决方案。如果有人建议我将不胜感激。

2 个解决方案

#1


0  

This should work perfectly. I believe, you are not making a POST request. Suggestion: If you are making the call from a form add

这应该完美。我相信,你没有发出POST请求。建议:如果您正在通过表单添加来电

method="POST" in form tag

表单标签中的method =“POST”

If you are making an ajax call $.ajax({ url:"url", type:"POST", data:"data" }).done();

如果你正在进行ajax调用$ .ajax({url:“url”,输入:“POST”,data:“data”})。done();

Tip: You can't make a post call,by simply hitting the url from browser. You have to use POSTMAN to make POST calls manually.

提示:您只需点击浏览器中的网址即可拨打电话。您必须使用POSTMAN手动进行POST调用。

#2


-1  

You should never use == to compare strings. Use === or strcmp to compare 2 strings.

你永远不应该使用==来比较字符串。使用===或strcmp比较2个字符串。

#1


0  

This should work perfectly. I believe, you are not making a POST request. Suggestion: If you are making the call from a form add

这应该完美。我相信,你没有发出POST请求。建议:如果您正在通过表单添加来电

method="POST" in form tag

表单标签中的method =“POST”

If you are making an ajax call $.ajax({ url:"url", type:"POST", data:"data" }).done();

如果你正在进行ajax调用$ .ajax({url:“url”,输入:“POST”,data:“data”})。done();

Tip: You can't make a post call,by simply hitting the url from browser. You have to use POSTMAN to make POST calls manually.

提示:您只需点击浏览器中的网址即可拨打电话。您必须使用POSTMAN手动进行POST调用。

#2


-1  

You should never use == to compare strings. Use === or strcmp to compare 2 strings.

你永远不应该使用==来比较字符串。使用===或strcmp比较2个字符串。