https://xxxx.localtunnel.me/api/user/registration

时间:2019-02-15 18:32:07

标签: android post android-volley

我正在尝试使用字符串请求齐射以json格式发送数据。我已经在stackoverflow和其他站点上正确地遵循了各种答案和教程,但是在这里我找不到解决方法:

这是错误:

    23:49:14.661 23745-23845/com.example.aditya.blood E/Volley: 
    [44973] BasicNetwork.performRequest: Unexpected response code 
    404 for https://xxxx.localtunnel.me/api/user/registration
    2019-02-15 23:49:14.663 23745-23745/com.example.aditya.blood 
    E/VOLLEY: com.android.volley.ClientError

这是我的代码:

    try
    {
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        String url = "https://xxxx.localtunnel.me/api/user/registration";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name",name.getText().toString().trim());
        jsonObject.put("dob",dob.getText().toString().trim());
        jsonObject.put("number",mAuth.getCurrentUser().getPhoneNumber());
        jsonObject.put("bloodGroup",blood.getText().toString().trim());
        JSONObject object = new JSONObject();
        object.put("lat","25.02");
        object.put("lng","21.02");
        jsonObject.put("location",object);

        final String requestbody = jsonObject.toString();

        StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.i("VOLLEY", response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("VOLLEY", error.toString());
            }
        }) {
            @Override
            public String getBodyContentType() {
                return "application/x-www-form-urlencoded,charset=utf-8";
            }

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

            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {
                String responseString = "";
                if (response != null) {
                    responseString = String.valueOf(response.statusCode);
                    // can get more details such as response.headers
                }
                return Response.success(responseString, HttpHeaderParser.parseCacheHeaders(response));
            }
        };

        stringRequest.setRetryPolicy(new DefaultRetryPolicy(
                0,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        requestQueue.add(stringRequest);


    }catch (JSONException e){
        e.printStackTrace();
    }

Accd。对我来说,错误可能是在超时或请求部分,但它似乎不起作用。 我已经尝试了所有关于stackoverflow的解决方案,但是似乎都没有。

0 个答案:

没有答案