简体   繁体   English

未返回Luracast Restler多格式XML

[英]Luracast Restler Multiformat XML not returned

i have a question regarding Luracast Restler v2. 我对Luracast Restler v2有疑问。

I have created my index.php with the following content: 我用以下内容创建了index.php:

require_once 'framework/restler.php';

spl_autoload_register('spl_autoload');

$r = new Restler();
$r->setSupportedFormats('JsonFormat', 'XmlFormat');
$r->addAPIClass('PROCESSOR');
$r->handle();

Now i have my processor.php with the following code sample - this is just a small part of the codebase ! 现在,我有了带有以下代码示例的processor.php- 这只是代码库的一小部分 :

class PROCESSOR {
    private $api_ver    = '0.1';
    private $allowed    = array('xxx.xxx.xxx.xxx');

    public function index( $request_data ) {
        if(empty($request_data)) throw new RestException(400,"parameter missing");
        $this->checkHost();
        $this->get_vars = $request_data;

    $result = new stdClass();               
    $result->version    = $this->api_ver;
        $result->timestamp  = date(DATE_RFC822);
        $result->generated  = $totaltime.' sec.';
        $result->type       = 'success';
        $result->filesize   = $this->res_filesize;
        $result->url        = $this->res_saved; 

        return $result;     
    }
}

My Problem is now, that when i send the request to http://api.myserver.xx/processor/?url=http://www.test.fr 我的问题是,当我将请求发送到http://api.myserver.xx/processor/?url = http://www.test.fr时

The API does what it has to do and returns JSON string. 该API会执行其操作并返回JSON字符串。

But when i type http://api.myserver.xx/processor .xml /?url=http://www.test.fr it also returns JSON - and not XML?!? 但是当我输入http://api.myserver.xx/processor .xml /?url=http://www.test.fr时,它还会返回JSON-而不是XML?!?

What's wrong here? 怎么了

Thanks. 谢谢。

JsonFormat不同, XmlFormat不包含在restler.php它存在于xmlformat.php确保已将其复制到与restler.php相同的文件夹中;如果仍无法正常工作,请尝试手动包含该类。

I found this post while dealing with the same issue. 我在处理同一问题时发现了这篇文章。 I have located an issue with the code, at least with the GitHub code retrieved on 13 Feb 2012. In the restler.php class function getResponseFormat() , starting at line 503, the extensions are pulled from the request url. 我已经找到了该代码的问题,至少是在2012年2月13日检索到的GitHub代码。在restler.php类函数getResponseFormat() ,从503行开始,扩展是从请求url中提取的。

The first line in the while loop (512) extracts the ".xml" extension just fine, but the following lines manipulate the variable so when the conditional statement evaluates $extension , it is no longer the expected value. while循环(512)中的第一行可以很好地提取".xml"扩展名,但是以下几行可以对变量进行操作,因此,当条件语句对$extension求值时,它不再是期望值。 I simply added a variable after the first line in the while loop to hold the original value of extension, then check if that value exists in the $format_map . 我只是在while循环的第一行之后添加了一个变量来保存扩展的原始值,然后检查该值是否存在于$format_map The example project works as expected once doing this. 完成后,示例项目将按预期工作。

FYI, I do not think this is a platform dependent issue, but if so, here is my environment: 仅供参考,我不认为这是平台相关的问题,但是如果是这样,那么这是我的环境:

OS: Mac OSX 10.7.3
PHP: v5.3.6
Apache: 2.2.21

Hope this helps. 希望这可以帮助。

In addition to Rhoderunner: I think the more precise bug is in line 514 of the restler.php file. 除了Rhoderunner:我认为更精确的错误在于restler.php文件的514行。 This line has to be: 该行必须是:

$extension = array_shift($extension);

and NOT : 不是

$extension = array_shift($extensions);

So we have to get rid of the s . 因此,我们必须摆脱s

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

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