0

私の HttpGet リクエストは、getAction ではなく、私の indexAction を呼び出しています。どうしたの?

ここに私のコードがあります:

    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 を呼び出します)。説明はありますか?

ありがとう。

4

1 に答える 1

0

私は答えを見つけました。これは実際には Zend Framework の動作です。GET リクエストで「id」要素が見つからない場合、getAction ではなく indexAction にリダイレクトされます。

例:

「GET localhost/student」は indexAction にリダイレクトされ、「GET localhost/student/23」は getAction にリダイレクトされます。(23はid)

Vikram Vaswani による Zend Framework: A Beginner's Guide で見つけました。

于 2011-12-27T06:51:49.377 に答える