2011-12-27 43 views
0

我的HttpGet请求正在调用我的indexAction,而不是getAction。这是怎么回事?Android HttpGet正在请求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() { 
} 

这里是我的代码在安卓

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),任何解释?

谢谢。

+0

你想要做什么?究竟是什么问题?清楚地提及它。 – 2011-12-27 06:44:02

+0

我正试图调用一个HttpGet,但它被重定向到indexAction,而不是getAction。 – VHanded 2011-12-27 06:47:17

回答

0

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

实施例:

'GET本地主机/学生将重定向到的indexAction,而 'GET本地主机/学生/ 23' 将重定向到的getAction。 (23是id)

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