Sending HTTP DELETE request in Android

后端 未结 9 1610
悲哀的现实
悲哀的现实 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条回答
  •  Happy的楠姐
    2020-12-15 04:31

    DELETE request is an extended form of GET request, as per the android documentation you cannot write in the body of DELETE request. HttpUrlConnection will throw "unable to write protocol exception".

    If you still want to write the parameter in the body, i suggest you to use the OKHttp Library.

    OKHttp documentation

    If you are intrested to use more simpler library then you can try SimpleHttpAndroid library

    One thing to remember here is if you are not writing anything in the body then remove the line

    conn.setDoOutput(true);
    

    Thanks, Hopefully it may help.

提交回复
热议问题