Android发送数据但服务器不会得到任何东西

时间:2014-05-04 15:13:10

标签: php android

Android代码:

private class getFilteredData extends AsyncTask<String, Void, Void> {
    private final HttpClient httpClient = new DefaultHttpClient();
    private String error = null;
    String temp;

    @Override
    protected void onPreExecute() {
    }

    @Override
    protected void onProgressUpdate(Void... progress) {
    }

    @Override
    protected Void doInBackground(String... params) {

        try {
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("min", 0);
                jsonObject.put("max", 100);
            } catch (JSONException e) {
                Log.d("DISHES", e.toString());
            }

            HttpPost post = new HttpPost(params[0]);
            post.addHeader(new BasicHeader("Content-Type", "application/json"));
            post.setEntity(new StringEntity(jsonObject.toString()));
            HttpResponse response = httpClient.execute(post);
            try {
                temp = EntityUtils.toString(response.getEntity());
            } catch (IOException e) {
                error = e.getMessage();
            }
        } catch (ClientProtocolException e) {
            error = e.getMessage();
            cancel(true);
        } catch (IOException e) {
            error = e.getMessage();
            cancel(true);
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        if (error == null) {
            Log.i("debugas", temp);
        } else {
            Log.e("DISHES", error);
        }
    }
}

PHP代码:

<?php
var_dump($_REQUEST);

此代码应将最小值和最大值发送到服务器,然后从服务器检索数据。但是当我从服务器检索数据后,我得到空的$ _REQUEST数组..

0 个答案:

没有答案