package co.globelist.atest;

import android.util.Log;

import com.android.volley.NetworkResponse;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.util.Map;


public class RestService {
    private String host = "http://192.168.1.2:3000/";
    public StringRequest getStringRequest(final Integer method, String path, final Map<String, String> params, final Callback callback) {
        final String url = host + path;

        Response.Listener<String> response = new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.d("RestService", "The result is: " + response);
                try {
                    JSONObject jsonResponse = new JSONObject(response);
                    callback.success(jsonResponse);
                } catch (JSONException e) {
                    callback.error("Format error!");
                }
            }
        };

        Response.ErrorListener error = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        };

        return new StringRequest(method, url, response, error) {
            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {
                String parsed;
                Log.d("RestService", "[" + method + "," + url + "] Response code: " + response.statusCode);
                Log.d("RestService", "[" + method + "," + url + "] Response headers: " + response.headers);
                try {
                    parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
                } catch (UnsupportedEncodingException e) {
                    parsed = new String(response.data);
                }
                return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
            }
            @Override
            protected Map<String, String> getParams()
            {
                return params;
            }
        };
    }
}

@@ -1479,734 +1479,8 @@
 ide%0A
-            protected Response%3CString%3E parseNetworkResponse(NetworkResponse response) %7B%0A                String parsed;%0A                Log.d(%22RestService%22, %22%5B%22 + method + %22,%22 + url + %22%5D Response code: %22 + response.statusCode);%0A                Log.d(%22RestService%22, %22%5B%22 + method + %22,%22 + url + %22%5D Response headers: %22 + response.headers);%0A                try %7B%0A                    parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));%0A                %7D catch (UnsupportedEncodingException e) %7B%0A                    parsed = new String(response.data);%0A                %7D%0A                return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));%0A            %7D%0A            @Override%0A
     

remove unnecessary function