0

As an old version of volley.jar. I pass params by following method:

@Override
public byte[] getBody() {
    if (params != null && params.size() > 0) {
        return encodeParameters(params, getParamsEncoding());
    }
    return null;
}                

But I need to update volley, and find that this method(encodeParameters()) was changed to private.

I also found that to override the method of getParams(), which did not work for me. the Method getBody of JsonObjectRequest is as following:

public byte[] getBody() {
    try {
        return mRequestBody == null ? null : mRequestBody.getBytes(PROTOCOL_CHARSET);
    } catch (UnsupportedEncodingException uee) {
        VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s",
            mRequestBody, PROTOCOL_CHARSET);
        return null;
    }
}

getParams() would never be called. so I cannot pass the params now.

I also tried to pass the params in the construct method which has JsonObject param, but it did not work either.

Mithun
  • 2,075
  • 3
  • 19
  • 26
BinqiangSun
  • 680
  • 6
  • 15

1 Answers1

0

hope I'm understanding you correctly.

an easier way to pass params with volley would be:

    String url = "some/url";

    Map<String, Object> jsonParams = new HashMap<>();
    jsonParams.put("someparam", getSomeParamObject());

    JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(jsonParams),
            new Response.Listener<JSONObject>()
            {
                @Override
                public void onResponse(JSONObject response)
                {
                 //do your magic...
                }
            }

for the encoding issue, see if this SO Question helps.

Hope this Helps.

Community
  • 1
  • 1
TommySM
  • 3,793
  • 3
  • 24
  • 36