首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Luracast Restler正在发送'text/html‘而不是JSON

Luracast Restler正在发送'text/html‘而不是JSON
EN

Stack Overflow用户
提问于 2012-05-02 17:19:15
回答 1查看 829关注 0票数 0

我有一个用LuraCast Restler API实现的REST web服务。到目前为止,它一直运行得很好。突然之间,我不再获得JSON数据来响应我对服务的请求。

X-Debug总是在每次请求服务时返回以下通知。

代码语言:javascript
复制
( ! ) Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/aem.davidcasillas.es/public/webservice/restler/restler.php on line 1136
Call Stack
#   Time    Memory  Function    Location
1   0.0013  631072  {main}( )   ../restIndex.php:0
2   0.0969  1170720 Restler->addAPIClass( ) ../restIndex.php:14
3   0.0971  1181912 Restler->generateMap( ) ../restler.php:248
4   0.0971  1184616 parse_doc( )    ../restler.php:652
5   0.0971  1184984 DocParser->parse( ) ../restler.php:1157
6   0.0972  1205520 DocParser->parseLines( )    ../restler.php:1073
7   0.0972  1209704 DocParser->parseLine( ) ../restler.php:1079
8   0.0973  1209944 DocParser->setParam( )  ../restler.php:1111
9   0.0973  1209944 DocParser->formatClass( )   ../restler.php:1120

( ! ) Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/aem.davidcasillas.es/public/webservice/restler/restler.php on line 1136
Call Stack
#   Time    Memory  Function    Location
1   0.0013  631072  {main}( )   ../restIndex.php:0
2   0.1065  1224952 Restler->addAuthenticationClass( )  ../restIndex.php:15
3   0.1065  1225304 Restler->addAPIClass( ) ../restler.php:260
4   0.1068  1228176 Restler->generateMap( ) ../restler.php:248
5   0.1068  1229568 parse_doc( )    ../restler.php:652
6   0.1068  1229936 DocParser->parse( ) ../restler.php:1157
7   0.1068  1239456 DocParser->parseLines( )    ../restler.php:1073
8   0.1068  1241448 DocParser->parseLine( ) ../restler.php:1079
9   0.1069  1241696 DocParser->setParam( )  ../restler.php:1111
10  0.1069  1241696 DocParser->formatClass( )   ../restler.php:1120

( ! ) Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/aem.davidcasillas.es/public/webservice/restler/restler.php:1136) in /Applications/MAMP/htdocs/aem.davidcasillas.es/public/webservice/restler/restler.php on line 385
Call Stack
#   Time    Memory  Function    Location
1   0.0013  631072  {main}( )   ../restIndex.php:0
2   0.1102  1228048 Restler->handle( )  ../restIndex.php:16
3   0.1233  1461248 Restler->sendData( )    ../restler.php:366
4   0.2814  1547080 header ( )  ../restler.php:385

( ! ) Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/aem.davidcasillas.es/public/webservice/restler/restler.php:1136) in /Applications/MAMP/htdocs/aem.davidcasillas.es/public/webservice/restler/restler.php on line 386
Call Stack
#   Time    Memory  Function    Location
1   0.0013  631072  {main}( )   ../restIndex.php:0
2   0.1102  1228048 Restler->handle( )  ../restIndex.php:16
3   0.1233  1461248 Restler->sendData( )    ../restler.php:366
4   0.2835  1547048 header ( )  ../restler.php:386

( ! ) Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/aem.davidcasillas.es/public/webservice/restler/restler.php:1136) in /Applications/MAMP/htdocs/aem.davidcasillas.es/public/webservice/restler/restler.php on line 387
Call Stack
#   Time    Memory  Function    Location
1   0.0013  631072  {main}( )   ../restIndex.php:0
2   0.1102  1228048 Restler->handle( )  ../restIndex.php:16
3   0.1233  1461248 Restler->sendData( )    ../restler.php:366
4   0.2846  1547064 header ( )  ../restler.php:387

( ! ) Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/aem.davidcasillas.es/public/webservice/restler/restler.php:1136) in /Applications/MAMP/htdocs/aem.davidcasillas.es/public/webservice/restler/restler.php on line 388
Call Stack
#   Time    Memory  Function    Location
1   0.0013  631072  {main}( )   ../restIndex.php:0
2   0.1102  1228048 Restler->handle( )  ../restIndex.php:16
3   0.1233  1461248 Restler->sendData( )    ../restler.php:366
4   0.2914  1547072 header ( )  ../restler.php:388

最后,数据是作为响应发送的,但不是JSON格式,所以我的movil应用程序不能再处理它。

正如我已经说过的那样,到目前为止,这项服务一直运行良好。我不知道这些通知是否与这个错误有关,但它们显然是相关的。

你能指出我该如何调试这个问题吗?

如果这能有任何帮助,这里是我的代码:

这是我的索引脚本,我在其中配置Restler:

代码语言:javascript
复制
<?php

require_once '../../BaseDatos.php';
require_once 'restler/restler.php';

#set autoloader
#do not use spl_autoload_register with out parameter
#it will disable the autoloading of formats
spl_autoload_register('spl_autoload');


$r = new Restler();
$r->setSupportedFormats('JsonFormat');
$r->addAPIClass('Rest');
$r->addAuthenticationClass('Seguridad');
$r->handle();

这是公共API类(我只展示了一个方法)

代码语言:javascript
复制
class Rest
{

    /**
     * @brief Una instancia de la clase BaseDatos
     *
     * @var BaseDatos $db
     */
    private $db;

    /**
     * \brief Constructor de la clase.
     *
     * Inicializa una instancia de la clase BaseDatos.
     *
     */
    function __construct() {
        $this->db = BaseDatos::getInstance();
    }
    public function getFuentes($nombreUsuario, $password) {

        $fuentes = $this->db->getFuentes();
        $fuentes = array('fuentes' => $fuentes);
        return $fuentes;
    }

下面是检索要返回的信息的BaseDatos类方法:

代码语言:javascript
复制
public function getFuentes() {
    //SELECT * FROM fuentes
    $queryString = 'SELECT * FROM ' . TABLA_FUENTES . ' ORDER BY nombreFuente';
    $queryResult = $this->query($queryString);
    if ($this->errno != 0) {
        //ERRRO. mysql
        $this->setErrorNoAndMessage(ErrorCode::ERROR_MYSQL, $this->error);
        return FALSE;
    }
    $resultado = array();
    while ($row = $queryResult->fetch_assoc() ) {
        $resultado[] = $row;
    }

    $this->resetErrorNoAndMessage();
    return $resultado;

}
EN

回答 1

Stack Overflow用户

发布于 2012-05-02 22:24:58

这个问题与我最近添加的Doc注释有关。我在类文档中添加的Restler标记产生了冲突,可能是因为@class的DocParser不处理这个特定的标记。

我在问题中提到的前两个注意事项发生在DocParser尝试执行formatClass()方法时,可能是响应@class标记,而不是响应PHP语言中的Class声明。

也许对此API有深入了解的人可以补充一些内容。

只需从文档中删除此标记,一切都可以正常工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10410881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档