DELETE 请求无效,Returns 状态码 200

DELETE Request not working , Returns status code 200

我正在尝试使用 android 中的 HttpUrlConnection 触发 DELETE 请求,我将 setRequest 方法设置为 DELETE 并获得 200 作为响应代码。该项目没有被删除。我正在使用的异步如下。

private class DeleteTask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        String result = null;
        URL url = null;
        try {
            url = new URL(urls[0]);
            Log.i("URL to access :", urls[0]);
        } catch (MalformedURLException exception) {
            exception.printStackTrace();
        }
        HttpURLConnection httpURLConnection = null;
        try {
            httpURLConnection = (HttpURLConnection) url.openConnection();
            httpURLConnection.setRequestMethod("DELETE");
            httpURLConnection.setRequestProperty("charset", "utf-8");
            httpURLConnection.setUseCaches(false);
            System.out.println("ResponseCode: "+httpURLConnection.getResponseCode());
            if(httpURLConnection.getResponseCode() == 204){
                Log.d(TAG,"Deleted");
            }
        } catch (IOException exception) {
            exception.printStackTrace();
        } finally {
            if (httpURLConnection != null) {
                httpURLConnection.disconnect();
            }
        }
        return null;
    }
    }
}

看起来 setRequestMethod() 没有工作,它将请求作为 GET 并给我一个 200!

我在 postman(一个 chrome 扩展)中测试了它,它工作正常,如果它是后端问题,那么 postman 也应该会失败。
好的http: 我也试图让这个在 okHttp 上工作

Request request = new Request.Builder().url(url.toString()).patch(body).build();

这个delete要怎么补,因为delete request dosent有一个body

沃尔利: 我也尝试了 google volly 库..

RequestQueue requestQueue = Volley.newRequestQueue(TimerSummary.this);
    StringRequest request = new StringRequest(Request.Method.DELETE, uri, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d(TAG,"Response: "+response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG,"Error: "+error);
        }
    });
    requestQueue.add(request);

这也 returns 类似于 GET 请求,我得到的项目是 json 应该被删除的。

如有任何建议,我们将不胜感激。 提前致谢..

居然打错了!!!我是个白痴!我的两种方法都可以正常工作,但我现在正在使用 Google 的 volly 库来处理网络相关的事情。

我在“?”之前少了一个“/”在使用 URL

附加参数之前