【问题标题】:Android HttpGet is requesting indexActionAndroid HttpGet 正在请求 indexAction
【发布时间】:2011-12-27 06:40:23
【问题描述】:

我的 HttpGet 请求正在调用我的 indexAction,而不是 getAction。怎么回事?

这是我的代码:

    public function getAction() {

    $id = $this->_getParam('id');

    if(!$id)
    {
        $this->getResponse()
             ->setHttpResponseCode(400)
             ->setBody("no id");
        return;
    }

    try
    {
        $q = Doctrine_Query::create()
             ->from('Milotin_Model_Locations l')
             ->where ('l.id=?', $id);

        $result = $q->fetchArray();

        if(count($result) == 1)
        {
            $this->getResponse()
                 ->setHttpResponseCode(200)
                 ->setBody(json_encode($result));
        }
    }
    catch(Exception $e)
    {
        $this->getResponse()
             ->setHttpResponseCode(500)
             ->setBody($e->getMessage());
    }
}



    public function indexAction() {
}

这是我在 Android 中的代码:

    private static void getLoc()
{
    final HttpResponse response;

    final HttpGet getRequest = new HttpGet(LOCATION_URI + "?geolat=" + geoLat + "&geolong=" + geoLong);

    try {
        response = mHttpClient.execute(getRequest);

        if(response.getStatusLine().getStatusCode() == 200)
        {
            //do something
        }

    } catch (ClientProtocolException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    }

}

我的 HttpPost 工作正常(它调用 postAction),有什么解释吗?

谢谢。

【问题讨论】:

  • 你到底想做什么?究竟是什么问题?说清楚。
  • 我试图调用 HttpGet,但它被重定向到 indexAction,而不是 getAction。

标签: android zend-framework-mvc zend-rest


【解决方案1】:

我找到了答案。这实际上是 Zend Framework 的行为。如果在 GET 请求中没有找到 'id' 元素,它将重定向到 indexAction,而不是 getAction。

例子:

'GET localhost/student' 将重定向到 indexAction,而 'GET localhost/student/23' 将重定向到 getAction。 (23 是 id)

在 Zend Framework:初学者指南中找到它,作者 Vikram Vaswani。

【讨论】:

    猜你喜欢
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    • 1970-01-01
    • 2013-12-22
    • 1970-01-01
    • 2013-01-23
    相关资源
    最近更新 更多