0

I am facing a problem in HttpDelete Request in android to send rest API. When I hit the API it shows error. There is a need of content-type and I am setting it in header but didn't find any solution I need help. And this is my code which I have tried:

 DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(nameValuePairs, "utf_8");
                url += "?" + paramString;
                HttpDelete httpDelete = new HttpDelete(url);
                httpDelete.setHeader("Iauth" ,"1");
                httpDelete.setHeader("Msessid" ,sessionid);
                httpDelete.addHeader("content-type","x-www-form-urlencoded");
                Log.d("URLLLLL",url);
               // httpPost.setHeader("content-type","application/x-www-form-urlencoded;charset=UTF-8");
                HttpResponse httpResponse = defaultHttpClient.execute(httpDelete);
                HttpEntity httpEntity = httpResponse.getEntity();
                inputStream = httpEntity.getContent();
Tom11
  • 2,419
  • 8
  • 30
  • 56

1 Answers1

0

Use HttpURLConnection because DefaultHttpClient is deprecated from API level 22

    URL url = new URL("http://www.example.com/resource");
    HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
    httpCon.setDoOutput(true);
    httpCon.addRequestProperty(
        "Content-Type", "application/x-www-form-urlencoded" );
   httpCon.addRequestProperty("Iauth" ,"1");
   httpCon.addRequestProperty("Msessid" ,sessionid);
    httpCon.setRequestMethod("DELETE");
    httpCon.connect();
USKMobility
  • 5,721
  • 2
  • 27
  • 34