Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除请求参数URL截取android_Android_Api_Android Volley - Fatal编程技术网

删除请求参数URL截取android

删除请求参数URL截取android,android,api,android-volley,Android,Api,Android Volley,我有一个API,带有如下的删除函数: String baseUrl ="http://localhost/v1/deletePost/"; String url = baseUrl + "3" //Here you change the ID, can put as variable // Request a string response from the provided URL. StringRequest stringRequest = new StringRequest(Reques

我有一个API,带有如下的删除函数:

String baseUrl ="http://localhost/v1/deletePost/";
String url = baseUrl + "3" //Here you change the ID, can put as variable

// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.DELETE, url, 
new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        // Display the first 500 characters of the response string.
        mTextView.setText("Response is: "+ response.substring(0,500));
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        mTextView.setText("That didn't work!");
    }
});
当我尝试使用postman时,通过在url:id like../deletePost/37中输入param成功

如何使用Volley库在android中实现/:id请求?

下面是一个关于如何使用Volley库的示例

在发送简单请求的页面上:

final TextView mTextView = (TextView) findViewById(R.id.text);
//...

// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://www.google.com";

// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, 
new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        // Display the first 500 characters of the response string.
        mTextView.setText("Response is: "+ response.substring(0,500));
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        mTextView.setText("That didn't work!");
    }
});
// Add the request to the RequestQueue.queue.add(stringRequest);

您只需使用URL字符串URL=http://localhost/v1/deletePost; 字符串id=/+3字符串finalUrl=url+id;你有任何示例代码吗?在我尝试之后,他的回答发出了400错误:02-10 11:16:12.877 25325-25368/?E/Volley:[4113]BasicNetwork.performRequest:@UpendraShahString DELETEADD=String id=/+id_post的意外响应代码400;字符串finalUrl=DELETEADD+id;请检查我的更新问题,我添加了照片@UpendraShahI在文档中没有找到它。好的,我会试试@Canato