首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Zend JSON服务器未返回内容

Zend JSON服务器未返回内容
EN

Stack Overflow用户
提问于 2012-04-04 20:29:45
回答 1查看 1.1K关注 0票数 1

我有一个zend JSON工厂,旨在为服务分发OTP,但是我无法让服务器实际返回任何内容。

代码语言:javascript
复制
<?php

class Application_Model_FrogconnectOTP
{
/**
 * Generates, stores, and returns the OTP for thesupplied user
 * 
 * @param   string  $username
 * @return  string
 */
public function generate($username)
{

     $hash = "Lol";
     return $hash;
}

/**
 * Will clear the OTP for the user.
 * 
 * @param   string  $username
 * @return  int
 */
public function delete($username) 
{
    return 1;
}
/**
 * Takes the supplied username and hash and will calculate new sums and verify the supplied hash.
 * 
 * @param   string  $username
 * @param   string  $hash
 * @return  int
 * 
 */
public function validate($username, $hash) {
    return 1;
}
}
?>

这个类是由缺省的(Ish) zend json服务器加载的,如下所示:

代码语言:javascript
复制
<?php
$this->_helper->layout->disableLayout();

$server = new Zend_Json_Server();
$OTPEngine = new Application_Model_FrogconnectOTP();
$server->setClass($OTPEngine);

if ('GET' == $_SERVER['REQUEST_METHOD']) {
    // Indicate the URL endpoint, and the JSON-RPC version used:
    $server->setTarget('/frogconnect')
           ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);

    // Grab the SMD
    $smd = $server->getServiceMap();

    // Return the SMD to the client
    header('Content-Type: application/json');
    echo $smd;
    return;
}
$server->handle();

但是,如果我尝试使用如下所示的json字符串发出请求,服务器将以204No Content标头作为响应,但我没有收到任何内容(我应该是"Lol“

代码语言:javascript
复制
{"method":"generate","params":{"username":"johndoe"}}

任何帮助都将不胜感激

EN

回答 1

Stack Overflow用户

发布于 2013-01-24 01:41:48

如果其他人有这个问题,这里的问题看起来是您试图强制web服务通过Zend MVC布局(我是根据处理代码顶部的disable布局推断的)。

建议您在公用文件夹中为JSON-RPC服务器创建自定义索引文件。

尝试创建文件,如下所示:

/public/api/v1.0/jsonrpc.php

代码语言:javascript
复制
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../../application'));

// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);

$application->bootstrap();

// Instantiate server, etc.
$server = new Zend_Json_Server();
$server->setClass('Application_Model_FrogconnectOTP');

if ('GET' == $_SERVER['REQUEST_METHOD']) {
    // Indicate the URL endpoint, and the JSON-RPC version used:
    $server->setTarget('/api/v1.0/jsonrpc.php')
       ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);

    // Grab the SMD
    $smd = $server->getServiceMap();

    // Return the SMD to the client
    header('Content-Type: application/json');
    echo $smd;
    return;
}

$server->handle();
?>

这将替换zend用于MVC内容的普通索引文件"/public/index.php“。

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

https://stackoverflow.com/questions/10011117

复制
相关文章

相似问题

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