从Android发送数据到PHP

时间:2017-05-29 17:27:24

标签: java php android json

我正在尝试将参数传递给我的php脚本。数据传递但总是返回“成功”为0.我通过在传递值后回显查询来测试php,它工作正常并放入所有数据。甚至var_dump($ _ POST)表示它接收数据但它总是返回“成功”为0.添加参数:

        params.add(new BasicNameValuePair("states", states));
        params.add(new BasicNameValuePair("min_budget", min_budget));
        params.add(new BasicNameValuePair("max_budget", max_budget));
        params.add(new BasicNameValuePair("activity", activity));
        Log.d("Passing parameters: ", params.toString());


        // Check your log cat for JSON response
        try {
            JSONObject json = jParser.makeHttpRequest(url_all_resorts, "POST", params);

makeHttpRequest方法:`

            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
            Log.d("Passing parameters 2: ", params.toString());

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            Log.d("Entity 2: ", httpEntity.toString());
            is = httpEntity.getContent();`

logcat

Log.d("Passing parameters 2: ", params.toString());
Passing parameters 2:: [states=Himachal Pradesh, min_budget=1,000, max_budget=9,000, activity=Leopard Safari]

收到logcat:

  Data received:: array(4) {
            ["states"]=>
            string(16) "Himachal Pradesh"
            ["min_budget"]=>
            string(5) "1,000"
            ["max_budget"]=>
            string(5) "9,000"
            ["activity"]=>
            string(14) "Leopard Safari"
          }

          {"success":0,"message":"No resort found"}

0 个答案:

没有答案