android-volley icon indicating copy to clipboard operation
android-volley copied to clipboard

can't send JsonObject with JsonObjectRequest

Open picachugame001 opened this issue 8 years ago • 1 comments

I'm trying with code:

public class VinhNT_HTTP implements Response.Listener<JSONObject>,Response.ErrorListener { private VinhNT_Activity context; private RequestQueue queue; public VinhNT_HTTP(VinhNT_Activity nguCanh){ context = nguCanh; // Instantiate the cache Cache cache = new DiskBasedCache(context.getCacheDir(), 1024 * 1024); // 1MB cap cache.clear(); // // Set up the network to use HttpURLConnection as the HTTP client. Network network = new BasicNetwork(new HurlStack()); // // Instantiate the RequestQueue with the cache and network. queue = new RequestQueue(cache,network);

    //


}
public  void sendRequest() {
    //
    queue.start();
    try{
        String url ="http://192.168.0.101/bongda";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("user","VinhNT");
        jsonBody.put("function", "login");
        JsonObjectRequest a = new JsonObjectRequest(Request.Method.POST,url,jsonBody,this,this);
        queue.add(a);
        //queue.stop();

    }
    /*catch (JSONException  e){
        Log.d("Error","JSONException");
    }*/
    catch (Exception e){
        Log.d("Error","JSONException"+ e.getMessage());
    }

}
public void cancelAll(){
    queue.cancelAll(context.getTitle_VinhNT());
}

@Override
public void onResponse(JSONObject response) {
    Log.d("Ket noi","OK roi nhe");
}

@Override
public void onErrorResponse(VolleyError error) {
    Log.d("Ket noi","Loi roi");
}

}

That doesn't send JSONObject to PHP server:

please help me, many thank

picachugame001 avatar Mar 25 '16 09:03 picachugame001

OK, I've fix it, Sory

picachugame001 avatar Apr 02 '16 15:04 picachugame001