drkj41932 2014-07-18 11:13
浏览 49

当我尝试从android发布我的JSON时,Zend $ _POST ['param_name']说“Undefined index”

my android function : im sure that there is no problem with MAP i put in the function

    public class WebServiceController extends  AsyncTask<WebServiceProperties, Void,   String> {

public static String makeRequest(String path, Map<?, ?> params ) throws Exception {

     HttpParams httpParameters = new BasicHttpParams();
        int timeoutConnection = 10000;
        HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
        DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);

        // url with the post data
        HttpPost httpost = new HttpPost(path);

        // convert parameters into JSON object
        JSONObject holder = new JSONObject(params);

        // passes the results to a string builder/entity
        StringEntity se = new StringEntity(holder.toString());

        // sets the post request as the resulting string
        httpost.setEntity(se);

        // sets a request header so the page receiving the request
        // will know what to do with it
        httpost.setHeader("Accept", "application/json");
        httpost.setHeader("Content-type", "application/json");


        // Handles what is returned from the page
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String httpResponse = httpclient.execute(httpost, responseHandler);
        return httpResponse;
  }


 @Override
 protected String doInBackground(WebServiceProperties... params) {
// TODO Auto-generated method stub
int count = params.length;
for (int i = 0; i < count; i++) {
    WebServiceProperties sp=params[i];
    try {
        return makeRequest(sp.getPath(), sp.getParams());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
return null;
 }



   }

this is my PHP controller :

 <?php

class ServiceController extends Zend_Controller_Action
{

public function init()
{

     $this->_response->setHeader('Content-Type', 'appication/json');
    $this->_response->setHeader('Access-Control-Allow-Origin', '*');
    $this->_response->setHeader('Access-Control-Max-Age', '3628800');
    $this->_response->setHeader('Access-Control-Allow-Methods', ' GET, POST, PUT,   DELETE');
    $this->_helper->viewRenderer->setNoRender(true);
    $this->_helper->layout->disableLayout(); 
  }

   public function indexAction()
  {



  }


  public function getVenuesAction()
  {
    $M_Venue = new Model_Venues();
    $venues = $M_Venue->selectVenuesDetails();
    echo Zend_Json::encode($venues);
  }
  public function getAuthAction()
  {
    $msg="";
    $res=false;
    $method=$_SERVER['REQUEST_METHOD'];
    try{
        $password=$_POST['password'];
        $venue_id=$_POST['venue_id'];
        $realpassword=md5($password);
        $mvenue=new Model_Venues();
        $venueRes=$mvenue->venueAuth($venue_id, $realpassword);
        $res=($venueRes)?true:false;
    }  catch (Exception $exc)
    {
        $msg=$exc->getMessage();
    }
    echo Zend_Json::encode(array("success"=>$res,'msg'=>$msg,'method'=>$method));
  }

}

$_POST['password'] and $_POST['venue_id'] throw "undefined index";

this is a photo captured when i debug params enter image description here

  • 写回答

1条回答 默认 最新

  • dongzong3053 2014-07-18 11:42
    关注

    Just to flesh out my comments. Something along this line should do it:

    class ServiceController extends Zend_Controller_Action
    {
      protected $json_data = array(); 
    
      public function init()
      {
    
        $this->_response->setHeader('Content-Type', 'appication/json');
        $this->_response->setHeader('Access-Control-Allow-Origin', '*');
        $this->_response->setHeader('Access-Control-Max-Age', '3628800');
        $this->_response->setHeader('Access-Control-Allow-Methods', ' GET, POST, PUT,   DELETE');
        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout->disableLayout(); 
        $request = $this->getRequest(); 
        $rawBody = $request->getRawBody(); 
        $json_data = Zend_Json::decode($rawBody);
      }
    
      public function getAuthAction() {
      // code....
            $password=$json_data['password'];
            $venue_id=$json_data['venue_id'];
      // code.....
      }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码