title: URL Encoding with Volley
body: <p>Does Android Volley do URL Encoding?</p>
  
  <p>I am trying to do a Get Request and on server side, it seems the URL being sent through is not encoded correctly.</p>
  
  <p>I have been fiddling with my CustomRequest class but am not able to get it working, if it does encoding.</p>
  
  <p>CustomRequest.java:</p>
  
  <pre><code>package com.bidorbuy.app.network;
  
  import com.android.volley.AuthFailureError;
  import com.android.volley.NetworkResponse;
  import com.android.volley.ParseError;
  import com.android.volley.Request; 
  import com.android.volley.Response;
  import com.android.volley.toolbox.HttpHeaderParser;
  
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.io.UnsupportedEncodingException;
  import java.net.URLEncoder;
  import java.util.Map;
  
  
  public class CustomRequest extends Request&lt;JSONObject&gt; {
  
  private Response.Listener&lt;JSONObject&gt; listener;
  private Map&lt;String, String&gt; params;
  private Map&lt;String, String&gt; headers;
  Priority priority;
  
  public CustomRequest(String url,
                       Map&lt;String, String&gt; params,
                       Map&lt;String, String&gt; headers,
                       Response.Listener&lt;JSONObject&gt; reponseListener,
                       Response.ErrorListener errorListener,
                       Priority priority)
  {
      super(Method.GET, url, errorListener);
      this.listener = reponseListener;
      this.params = params;
      this.headers = headers;
      this.priority = priority;
  }
  
  public CustomRequest(int method,
                       String url,
                       Map&lt;String, String&gt; params,
                       Map&lt;String, String&gt; headers,
                       Response.Listener&lt;JSONObject&gt; reponseListener,
                       Response.ErrorListener errorListener,
                       Priority priority) {
      super(method, url, errorListener);
      this.listener = reponseListener;
      this.params = params;
      this.headers = headers;
      this.priority = priority;
  }
  
  protected Map&lt;String, String&gt; getParams()
          throws com.android.volley.AuthFailureError {
      return params;
  };
  
  @Override
  public Map&lt;String, String&gt; getHeaders() throws AuthFailureError {
      return headers;
  }
  
  @Override
  public byte[] getBody() throws AuthFailureError {
      Map&lt;String, String&gt; params = getParams();
      if(params!=null &amp;&amp; params.size() &gt; 0){
          return encodeParameters(params, getParamsEncoding());
      }
      return null;
  }
  
  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;');
          }
          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));
          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) {
      listener.onResponse(response);
  }
  
  
  }
  </code></pre>
  
  <p>and then I use the request elsewhere in the app as seen below:</p>
  
  <pre><code>    public void getRequest(String url, Map&lt;String, String&gt; params, final String source) {
  
      getHeaders(headers);
  
      CustomRequest jsObjRequest = new CustomRequest(Request.Method.GET, url, params, headers, getReponse(source), createMyReqErrorListener(), Constants.PRIORITY_HIGH);
      queue.add(jsObjRequest);
  
  }
  </code></pre>
  
  <p>and this is the code i am passing the params through to be used in the network call:</p>
  
  <pre><code>    private void forgotPasswordExecute() {
      forgotPasswordButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
              LocalBroadcastManager.getInstance(ForgotPasswordActivity.this).registerReceiver(forgotPasswordReceiver, new IntentFilter(Constants.WS_FORGOT_PASSWORD));
              params.put("emailAddress", "some@email.com");
  
  
              String url = Constants.FORGOT_PASSWORD_URL;
              request.getRequest(url, params, "ForgotPassword");
              System.out.println("URL is: " + url);
          }
      });
  }
  </code></pre>
  
  <p>I just need some assistance with the encoding of the URL in volley. If volley does not do it, is there another way i could encode the URL and still use Volley?</p>
  
  <p>Thanks</p>