Search in sources :

Example 1 with BaseRequest

use of im.amomo.volley.sample.BaseRequest in project OkVolley by googolmo.

the class RequestFragment method post.

private void post() {
    BaseRequest request = new BaseRequest(Request.Method.POST, "http://192.168.2.19:5000/test1", new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject jsonObject) {
            Toast.makeText(getActivity(), jsonObject.toString(), Toast.LENGTH_SHORT).show();
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof ServerError) {
                Toast.makeText(getActivity(), new String(((ServerError) error).networkResponse.data, Charset.defaultCharset()), Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    });
    //        request.form("text", "test " + SystemClock.elapsedRealtime());
    request.setTag("request");
    OkVolley.getInstance().getRequestQueue().add(request);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) ServerError(com.android.volley.ServerError) BaseRequest(im.amomo.volley.sample.BaseRequest)

Example 2 with BaseRequest

use of im.amomo.volley.sample.BaseRequest in project OkVolley by googolmo.

the class RequestFragment method load.

private void load() {
    OkRequest request = new BaseRequest(Request.Method.GET, "https://api.douban.com/v2/user/googolmo", new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject jsonObject) {
            Toast.makeText(getActivity(), jsonObject.toString(), Toast.LENGTH_SHORT).show();
            Toast.makeText(getActivity(), jsonObject.optString("name"), Toast.LENGTH_SHORT).show();
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show();
        }
    });
    request.setTag("request");
    OkVolley.getInstance().getRequestQueue().add(request);
}
Also used : OkRequest(im.amomo.volley.OkRequest) Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) BaseRequest(im.amomo.volley.sample.BaseRequest)

Aggregations

Response (com.android.volley.Response)2 VolleyError (com.android.volley.VolleyError)2 BaseRequest (im.amomo.volley.sample.BaseRequest)2 JSONObject (org.json.JSONObject)2 ServerError (com.android.volley.ServerError)1 OkRequest (im.amomo.volley.OkRequest)1