Sending HTTP DELETE request in Android

后端 未结 9 1608
悲哀的现实
悲哀的现实 2020-12-15 04:02

My client\'s API specifies that to remove an object, a DELETE request must be sent, containing Json header data describing the content. Effectively it\'s the same call as ad

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 04:38

    Try below method for call HttpDelete method, it works for me, hoping that work for you as well

    String callHttpDelete(String url){
    
                 try {
                        HttpParams httpParams = new BasicHttpParams();
                        HttpConnectionParams.setConnectionTimeout(httpParams, 15000);
                        HttpConnectionParams.setSoTimeout(httpParams, 15000);
    
                        //HttpClient httpClient = getNewHttpClient();
                        HttpClient httpClient = new DefaultHttpClient();// httpParams);
    
    
                        HttpResponse response = null;    
                        HttpDelete httpDelete = new HttpDelete(url);    
                        response = httpClient.execute(httpDelete); 
    
                        String sResponse;
    
                        StringBuilder s = new StringBuilder();
    
                        while ((sResponse = reader.readLine()) != null) {
                            s = s.append(sResponse);
                        }
    
                        Log.v(tag, "Yo! Response recvd ["+s.toString()+"]");
                        return s.toString();
                    } catch (Exception e){
                        e.printStackTrace();
                    }
                  return s.toString();
            }
    

提交回复
热议问题