2016-11-01 09:10
浏览 88


I want to send a request to database using Volly in android. This is my request

private class MyAsyncTask extends AsyncTask<String, Integer, Double>{

    protected Double doInBackground(String... params) {
        // TODO Auto-generated method stub
        return null;

    protected void onPostExecute(Double result){
        Toast.makeText(getApplicationContext(), "Code Sent", Toast.LENGTH_LONG).show();
    protected void onProgressUpdate(Integer... progress){

    public void postData(String valueIWantToSend) {
        try {
            RequestQueue requestQueue = Volley.newRequestQueue(mContexy);
            String URL = Config.Get_FeedBackURL;
            JSONObject jsonBody = new JSONObject();
            jsonBody.put("email", SharedPrefs.getString(mContexy, SharedPrefs.KEY_email," "));
            jsonBody.put("ID", "");
            jsonBody.put("Author", SharedPrefs.getString(mContexy, SharedPrefs.KEY_name," "));
            jsonBody.put("comment", valueIWantToSend);
            final String mRequestBody = jsonBody.toString();

            StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
                public void onResponse(String response) {
                    Log.i("VOLLEY", response);
            }, new Response.ErrorListener() {
                public void onErrorResponse(VolleyError error) {
                    Log.e("VOLLEY", error.toString());
            }) {
                public String getBodyContentType() {
                    return "application/json; charset=utf-8";

                public byte[] getBody() throws AuthFailureError {
                    try {
                        return mRequestBody == null ? null : mRequestBody.getBytes("utf-8");
                    } catch (UnsupportedEncodingException uee) {
              "Unsupported Encoding while trying to get the bytes of %s using %s", mRequestBody, "utf-8");
                        return null;

                protected Response<String> parseNetworkResponse(NetworkResponse response) {
                    String responseString = "";
                    if (response != null) {
                        responseString = String.valueOf(response.statusCode);
                        responseString = String.valueOf(;

                        // can get more details such as response.headers
                    return Response.success(responseString, HttpHeaderParser.parseCacheHeaders(response));

        } catch (JSONException e) {


It sends request into php webservice but I can not handle it,I used this code in my php file

 $json = file_get_contents('php://input');
$objd = json_decode($_POST);

echo $objd["ID"];
//"ID", ""
     if ($objd["ID"]== "") {

        echo $obj["email"];
        echo $obj["Author"];
        echo $obj["comment"];

        //fetch product id from ibecon
        $stmt = $this->db->prepare("INSERT INTO `userComments`(`useremail`, `username`, `text`) VALUES ('as','dd','dddd')");


        sendResponse(200, json_encode($obj));         

        return true;

    }else if(isset($_GET["companyid"])){

        sendResponse(203, json_encode($result));          

        return false;



Php return PHP Warning: json_decode() expects parameter 1 to be string, array given in and then return status code of 200.I want to know How can I handle posted data in php file. Thanks

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题