2011-12-27 2 views
0

私のHttpGetリクエストがgetActionではなくindexActionを呼び出しています。どうしたの?ここで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() { 
} 

そして、ここでは、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を呼び出す)が正しくどれ説明を働いていますか?

ありがとうございました。

+0

正確に何をしようとしていますか?問題は何ですか?明確に言及してください。 –

+0

私はHttpGetを呼び出そうとしていましたが、getActionではなくindexActionにリダイレクトされています。 – VHanded

答えて

0

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

例:

が は 'localhostの/学生/ 23をGET' ながら、indexActionにリダイレクトされます 'localhost /を生徒がGET' をgetActionにリダイレクトされます。 (23はIDです)

Zend Frameworkで見つけたのは、Vikram Vaswaniの初心者向けガイドです。

関連する問題