Unable to mimmick POSTMAN request in Volley
<p>I am new to using Volley on Android. Using the old http client stuff I could make my web requests perfectly with the various headers and parameters, now I am unable. My request looks like this in Postman:</p>

<pre><code>POST /token HTTP/1.1
Host: my.api.co.za
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache

username=test&amp;password=1234&amp;grant_type=password
</code></pre>

<p>Yet I am unable to recreate and execute this request in Volley. I have tried making a custom Json request class that extends <code>Request&lt;JSONObject&gt;</code> but to no avail. Please see my code below:</p>

<pre><code>public class CustomJsonRequest extends Request&lt;JSONObject&gt; {

    private Response.Listener&lt;JSONObject&gt; listener;
    private Map&lt;String, String&gt; params;

    public CustomJsonRequest(int method, String url, Listener&lt;JSONObject&gt; responseListener, ErrorListener errorListener) {
        super(method, url, errorListener);
        this.listener = responseListener;
    }

    @Override
    public Map getHeaders() throws AuthFailureError {
        Map headers = new HashMap();
        headers.put("Accept", "application/json");
        headers.put("Content-Type", "application/x-www-form-urlencoded");
        return headers;
    }

    @Override
    public byte[] getBody() throws AuthFailureError {
        HashMap&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
        params.put("username", "test");
        params.put("password", "1234");
        params.put("grant_type", "password");
        if (params != null &amp;&amp; params.size() &gt; 0) {
            return encodeParameters(params, getParamsEncoding());
        }
        return null;
    }

    /**
     * Converts &lt;code&gt;params&lt;/code&gt; into an application/x-www-form-urlencoded encoded string.
     */
    private byte[] encodeParameters(Map&lt;String, String&gt; params, String paramsEncoding) {
        StringBuilder encodedParams = new StringBuilder();
        try {
            for (Map.Entry&lt;String, String&gt; entry : params.entrySet()) {
                encodedParams.append(URLEncoder.encode(entry.getKey(), paramsEncoding));
                encodedParams.append('=');
                encodedParams.append(URLEncoder.encode(entry.getValue(), paramsEncoding));
                encodedParams.append('&amp;');
            }
            encodedParams.deleteCharAt(encodedParams.lastIndexOf("&amp;"));
            Log.e("params", encodedParams.toString());
            return encodedParams.toString().getBytes(paramsEncoding);
        } catch (UnsupportedEncodingException uee) {
            throw new RuntimeException("Encoding not supported: " + paramsEncoding, uee);
        }
    }

    @Override
    protected Response&lt;JSONObject&gt; parseNetworkResponse(NetworkResponse response) {
        try {
            String jsonString = new String(response.data,
                    HttpHeaderParser.parseCharset(response.headers));
            Log.e("response", response.toString());
            return Response.success(new JSONObject(jsonString),
                    HttpHeaderParser.parseCacheHeaders(response));
        } catch (UnsupportedEncodingException e) {
            return Response.error(new ParseError(e));
        } catch (JSONException je) {
            return Response.error(new ParseError(je));
        }
    }

    @Override
    protected void deliverResponse(JSONObject response) {
        // TODO Auto-generated method stub
        Log.e("response", response.toString());
        listener.onResponse(response);
    }

    private Priority mPriority;

    public void setPriority(Priority priority) {
        mPriority = priority;
    }

    @Override
    public Priority getPriority() {
        return mPriority == null ? Priority.NORMAL : mPriority;
    }
}
</code></pre>

<p>And I call this as follows in my <code>MainActivity</code> class: </p>

<pre><code>CustomJsonRequest request = new CustomJsonRequest(Request.Method.POST, AUTH_URL, new Response.Listener&lt;JSONObject&gt;() {
            @Override
            public void onResponse(JSONObject response) {
                //showJSON(response);
                VolleyLog.v("Response:%n %s", response);
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                txtError(error);
            }
        });
</code></pre>

<p>Can somebody tell me where I am going wrong in creating this request?</p>