1

I have simple question which method to call on POST and which method to call on GET.

This is my simple Class:

public class CustomStringRequest extends Request<CustomNetworkResponse> {

private final Map<String, String> headers;
private final Map<String, String> params;
private final String body;
private final Response.Listener<CustomNetworkResponse> listener;


public CustomStringRequest(int method,
                           String url,
                           Map<String, String> headers,
                           Map<String, String> params,
                           String body,
                           Response.Listener<CustomNetworkResponse> listener,
                           Response.ErrorListener errorListener) {

    super(method, url, errorListener);
    this.headers = headers;
    this.params = params;
    this.body = body;
    this.listener = listener;
}



@Override
public Map<String, String> getHeaders() throws AuthFailureError {
    return headers != null ? headers : super.getHeaders();
}

@Override
public Map<String, String> getParams() {
    return params;
}

@Override
public byte[] getBody() throws AuthFailureError {
    return body != null ? body.getBytes() : null;
}

How can I use getParams() and getBody() at the same time? Is it possible, because when I check the super implementation I assume it's impossible.

I also commented out the method getBody() to see thats true.

Does that mean that i can't send POST with body and also url parameters? Are url parameters meant to be used for GET request?? Is this standard?

5er
  • 2,506
  • 7
  • 32
  • 49
  • I think they are the same, since getParams called inside default getBody – BNK Oct 24 '15 at 04:54
  • @BNK, yes it seems like. It strange to me that there is no method to create UrlParametrs (well its deprecated... but still I don't believe that worked as UrlParams). Or am I missing something , and there is a method for that? – 5er Oct 24 '15 at 22:11
  • Do you mean the params in the url of GET requests? – BNK Oct 24 '15 at 22:35
  • No. In the POST. I need to make POST request with urlParams and body. I implemented this my self, for now. (Concatenation of url and urlParameters). If there is a methot that cover that concatenation it should work for get and post request, right? – 5er Oct 25 '15 at 23:07

1 Answers1

0

Well I am not sure what your intentions with that! You can always append the url with your url parameters (If the parameters are that simple). And Then You can use getParams() or getBody() to pass more complex parameters.

I think the difference between those two is the encoding of your parameters while they travel through the network (though I am not 100% sure with this) but Yes. getBody() more secure.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72