【问题标题】:How to write REST web service in cakephp using Post ..? [closed]如何使用 Post .. 在 cakephp 中编写 REST Web 服务? [关闭]
【发布时间】:2011-06-02 10:38:24
【问题描述】:

我正在尝试创建一个用于登录 cakephp 的 REST Web 服务,现在我想通过 http post 方法将用户 ID 和密码作为 cakephp 中的 JSON 发送。 谢谢

【问题讨论】:

  • 谷歌是你的朋友:book.cakephp.org/view/1238/REST
  • 你想要什么?启动 RESTful 服务还是从 CakePHP 调用 RESTful 服务?
  • 请考虑改进您的问题。您当前形式的问题不包含足够的详细信息。请阅读FAQHow to Ask 部分,了解如何改进您的问题。如果问题不清楚,您的赏金将无法帮助您获得答案。
  • 我们需要更多细节——尤其是因为你几乎不接受任何人的回答。

标签: json cakephp rest post


【解决方案1】:

你可以在 cakephp 中通过 Http post 发送 json

    <?php
 $data = array('Users'=>array('id'=>'1','username'=>'xyz','password'=>'pass','email'=>'xyz@xya.com','age'=>'28','gender'=>'male')); 
$url = "http://localhost/appname/Controllername/functionname";


    $content = json_encode($data);

    $curl = curl_init($url);

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, 'data='.$content);
    $json_response = curl_exec($curl);
    echo $json_response;?>

【讨论】:

  • 嗨,Abba Bryant,我期待这样的事情,如果有比这更好的事情,我会奖励他们。
  • 你应该使用 HttpSocket 而不是 curl。
猜你喜欢
  • 2014-02-14
  • 2023-04-06
  • 1970-01-01
  • 1970-01-01
  • 2010-09-24
  • 1970-01-01
  • 1970-01-01
  • 2018-01-17
  • 1970-01-01
相关资源
最近更新 更多