如何通过发送Json Raw在齐射中发出发帖请求?

时间:2019-03-10 19:05:47

标签: android json post android-volley

我想在体内发送json原始文件,我该如何用凌空抽射。  提供的邮递员图片 enter image description here 每当我尝试它都会给出空结果

我使用-

 RequestQueue requestQueue = Volley.newRequestQueue(this);
        String URL = "http://35.229.120.166/test.php";
        JSONObject jsonBody = new JSONObject();
        try {
            jsonBody.put("firstkey", "firstvalue");
        } catch (JSONException e1) {
            e1.printStackTrace();
        }
        try {
            jsonBody.put("secondkey", "secondobject");
        } catch (JSONException e1) {
            e1.printStackTrace();
        }
        final String mRequestBody = jsonBody.toString();

        StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
Log.v("ANUJ",response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }) {
            @Override
            public String getBodyContentType() {
                return "application/json; charset=utf-8";
            }

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


        };

        requestQueue.add(stringRequest);

任何人都可以解决。 我试图以原始格式在体内发送json数据,但对我不起作用。

0 个答案:

没有答案