Volley Request with Raw data

前端 未结 2 1205
难免孤独
难免孤独 2021-01-15 21:55

In my application I have to send POST request with JSON req param, I tried to create request with Postman Rest Client and it is working fine but not working with below code.

2条回答
  •  暖寄归人
    2021-01-15 22:39

    hope this isn't too late.

    Have you tried a different type of request, like String or JsonObject? And a different syntax for the params?

    e.g.

         Map jsonParams = new ArrayMap<>();
        jsonParams.put("nodeId", null);
        jsonParams.put("userId", null);
        jsonParams.put("mobileNumber", "sharma@gmail.com");
        jsonParams.put("userProfile", null);
        jsonParams.put("region", null);
        jsonParams.put("countryCode", 91);
        jsonParams.put("password", pass@123);
        jsonParams.put("places", new ArrayList());
        jsonParams.put("trustedNetwork", new ArrayList());
        jsonParams.put("profilePic", null);
        jsonParams.put("fullName", null);
        jsonParams.put("longitude", 0.0);
        jsonParams.put("latitude", 0.0);
    
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(jsonParams),
                new Response.Listener()
                {
                    @Override
                    public void onResponse(JSONObject response)
                    {
                      mResponseListener.requestCompleted(response);
                    }
                },
                new Response.ErrorListener()
                {
                    @Override
                    public void onErrorResponse(VolleyError error)
                    {
                        if (null != error.networkResponse)
                        {
                         mResponseListener.requestEndedWithError(error);
                        }
                    }
                });
    

    Also, have a look at this SO question. Hope any of this helps.

提交回复
热议问题