在Android VolleyRequest中将参数发送到PostMethod时获取404响应

时间:2018-12-15 05:35:14

标签: android request android-volley

我只是想在PostMethod中发送Params并获取404响应。我尝试了许多解决方案,例如 this。但是对我没有任何帮助。

这是我实际尝试的代码。

    HashMap<String, String> headers = new HashMap<>();
                headers.put("value", phone);
                headers.put("type", "phone");
           VolleyHelperPost.callVolleyHelperPost(/*Constants.GET_MEMBERSHIP_ID*/"https://myUrl.org/forgotmembershipIDWeb?value="+""+phone+"&type=phone",
                        Constants.NOTIFICATION_GET_MEMBERSHIP_DETAILS,
                        this, headers, "");

and its implementation was 


 public static void callVolleyHelperPost(String requestUrl,
                                            final String reqRype,
                                            final Context context,
                                            final Map<String, String> bodyParams, String name) {


     StringRequest request = new StringRequest(Request.Method.POST, serverURL, new Response.Listener<String>() {
                            @Override
                            public void onResponse(String response) {

                                System.out.println("Success response:--->" + response);
                                if (progressDialog != null) {
                                    progressDialog.dismiss();
                                    progressDialog = null;
                                }
                                UserNotification.notify(reqRype, response);
                                UserNotification.notifyFragment(reqRype, response);
                            }
                        }, new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError volleyError) {
        }


                        @Override
                        protected Map<String, String> getParams() throws AuthFailureError {
                            if (bodyParams != null) {
                                Log.d("params", "==========" + bodyParams.toString());
                                return bodyParams;
                            } else {
                                return super.getParams();
                            }
                        }
                        @Override
                        public String getBodyContentType() {
                            return application/json;
                        }
}

这是我的邮递员要求 enter image description here

2 个答案:

答案 0 :(得分:0)

您可以使用以下命令发送发帖请求。无需覆盖// Provide a range of values for determining what you'll consider to be an "overlap" // (instead of checking neighboring x/y coords.) function inRange(valueA, rangeA, rangeB) { return valueA >= rangeA && valueA <= rangeB; } // Provide adapters for tooltipText so we can modify them on the fly chart.series.each(function(series) { series.bullets .getIndex(0) .adapter.add("tooltipText", function(tooltipText, target) { // the other data fields will already match on the date/x axis, so skip // the date and this bullet's data fields. // (target.dataItem.component is the target's series.) var skipFields = ["date", target.dataItem.component.dataFields.valueY]; // this bullet's value var hoveredValue = target.dataItem.valueY; // all the other data fields at this date var data = target.dataItem.dataContext; // flag for adding additional text before listing other nearby bullet values var otherPoints = false; Object.keys(target.dataItem.dataContext).forEach(function(field) { // if the field is neither date, nor bullet's if (!~skipFields.indexOf(field)) { if (inRange(data[field], hoveredValue - 0.5, hoveredValue + 0.5)) { if (!otherPoints) { tooltipText += "\n\nOthers:"; otherPoints = true; } // Keep {data placeholder} notation to retain chart formatting features tooltipText += "\n" + field + ": {" + field + "}°C"; } } }); return tooltipText; }); });

getParams

答案 1 :(得分:0)

您应该在网址末尾附加参数,因为您的参数不是x <- c("12-01-2010 08:26", "12-01-2010 08:26", "12-01-2010 08:26", "2/17/2011 11:05", "2/17/2011 11:05") 形式参数

所以您的网址应该是邮递员上的网址。

url是: query params并删除您的getParam()方法