【问题标题】:Post Web Service in codeigniter using REST Server not working and showing error使用 REST 服务器在 codeigniter 中发布 Web 服务不工作并显示错误
【发布时间】:2014-09-22 02:32:54
【问题描述】:

我是 codeigniter 的新手,我正在使用 Phil Sturgeon 的 REST 服务器来提供“发布”类型的 Web 服务。尽管我的“get”类型的 Web 服务运行良好。下面是我用于发布网络服务的控制器代码。

require(APPPATH.'libraries/REST_Controller.php');

class json 扩展 REST_Controller {

public function __construct()   {

    parent::__construct();

}

public function data_post() {

    $user = array(
        'id' => $params['id']
    );

    $this->response(array('status'=>'success'), 200);

}

}

我正在使用 rest add on 检查网络服务是否正常工作,但我遇到了错误。

致命错误:未捕获的异常 'Exception' 带有消息“格式类不支持从“php”转换。'在 /home/magnetic/public_html/touch/order-form/application/libraries/Format.php:51 堆栈跟踪:#0 /home/magnetic/public_html/touch/order-form/application/libraries/Format.php(31 ): Format->__construct('{"id": "restCli...', 'php') #1 /home/magnetic/public_html/touch/order-form/application/libraries/REST_Controller.php(247): Format->factory('{"id": "restCli...', 'php') #2 /home/magnetic/public_html/touch/order-form/application/controllers/json.php(6): REST_Controller- >__construct() #3 /home/magnetic/public_html/touch/order-form/system/core/CodeIgniter.php(308): json->__construct() #4 /home/magnetic/public_html/touch/order-form /index.php(202): require_once('/home/magnetic/...') #5 {main} 在 /home/magnetic/public_html/touch/order-form/application/libraries/Format.php 上线51

http://awesomescreenshot.com/0cd38frz01 是rest插件错误截图

如果我的代码中还有任何内容,请让我知道我还需要做什么,并请让我知道使用 REST 服务器进行“发布”Web 服务的整个过程。 提前致谢

【问题讨论】:

    标签: php json web-services codeigniter codeigniter-restserver


    【解决方案1】:

    在 RESTClient 的正文中,尝试发送:

    id=restClient%20Test
    

    而不是

    {"id": "restCliente Test"}
    

    【讨论】:

    • 感谢您的回复,但这不是问题所在。虽然我试过了。
    • @RobertMiles 您是否检查过参数Content-type: application/x-www-form-urlencoded 是否在请求标头中发送?这个可以吗..
    • 怎么样?请举例说明
    • 在 RESTClient 中,点击“Headers > Custom header”。关注打印屏幕:http://snag.gy/to3Nh.jpg
    • 但这适用于单值如果我必须发送多个值,如 id、电子邮件等。我使用 {"id":1;"email":"xyz@abc.com"这是返回 false 而不是值。我是否需要更改标题或其他任何内容。请让我知道并提前感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 2013-05-23
    • 1970-01-01
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多