获取请求参数y体

efzxgjgh  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(227)

关闭。这个问题需要详细或明确。它目前不接受答案。
**想改进这个问题吗?**编辑这篇文章,添加细节并澄清问题。

17小时前关门了。
改进这个问题
这是一个截击(Android)La CuaaL的TayaMeta Survivin损坏的UN正文。此资源不支持推断的媒体类型“应用程序/八位字节流”-这是我的工作。
Postman : Postman : Postman , Postman , Postman , Postman , Postman , Postman , Postman , Postman , Postman , Postman , Postman , Postman , Postman , Postman , Postman
你想让我做决定吗?
科迪戈:

public void getOrderRegister(Company company, Order order, @NonNull Response.Listener<List<Order>> onSuccess, @NonNull Response.ErrorListener onError) {

    User user = app.loadCredentials();

    Gson gson = Utils.getGson();
    final String jsonOrder = gson.toJson(order);

    HashMap<String, String> params = new HashMap<>();
    params.put("user", user.getUsername());
    params.put("pass", user.getPassword());
    params.put("url", company.getUrl());
    params.put("db", company.getBD());

    final String url = "www.example.com";

    RequestQueue requestQueue = Volley.newRequestQueue(app);

    final String mRequestBody = jsonOrder.toString();

    StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.i("LOG_RESPONSE", response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("LOG_RESPONSE_ERROR", error.toString());
        }
    }) {
        @Override
        public String getBodyContentType() {
            return "application/json; text/utf_8";
        }

        @Override
        public byte[] getBody() throws AuthFailureError {
            return mRequestBody.getBytes(StandardCharsets.UTF_8);
        }

        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            return params;
        }

        @Override
        public String getUrl() {

                StringBuilder stringBuilder = new StringBuilder(url);
                Iterator<Map.Entry<String, String>> iterator = params.entrySet().iterator();
                int i = 1;
                while (iterator.hasNext()) {
                    Map.Entry<String, String> entry = iterator.next();
                    if (i == 1) {
                        stringBuilder.append("?").append(entry.getKey()).append("=").append(entry.getValue());
                    } else {
                        stringBuilder.append("&").append(entry.getKey()).append("=").append(entry.getValue());
                    }
                    iterator.remove(); // avoids a ConcurrentModificationException
                    i++;
                }
                url = String.valueOf(stringBuilder);

            return url;
        }

        @Override
        protected Response<String> parseNetworkResponse(NetworkResponse response) {
            String responseString = "";
            if (response != null) {
                responseString = String.valueOf(response.statusCode);
            }
            return Response.success(responseString, HttpHeaderParser.parseCacheHeaders(response));
        }
    };

    requestQueue.add(stringRequest);
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题