Неожиданный код ответа 404 для https://xxxx.localtunnel.me/api/user/registration - PullRequest
0 голосов
/ 15 февраля 2019

Я пытаюсь отправить данные в формате 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();
    }

акк.для меня ошибка либо в части таймаута, либо в части запроса, но, похоже, она не работает.Я перепробовал все решения на stackoverflow, но, похоже, ни одно из них не работает.

...