I have a simple Restful service being called from a console app so am using WebClient
. I am wondering if this call for Delete is correct.
The url looks like localhost/RestService1/Person/1
using (var client = new WebClient())
{
client.UploadString(url, "DELETE", "");
}
I don't like that UploadString
does not have an overload without a data
parameter. The passing of an empty parameter is not sitting well with me. Is there a better method to use for a DELETE
?
I could use WebRequest
but I want to just use WebClient
to keep it consistent.
Here is the WebRequest
block
var request = WebRequest.Create(url);
request.Method = "DELETE";
var response = (HttpWebResponse)request.GetResponse();
Both blocks work fine but what is best? Or is there a better way?
WebClient
really gives you the semantics of DELETE.Webclient
just usesWebRequest
(HttpWebRequest
) under the covers, so I think usingHttpWebRequest
) directly is more readable. – Fibrinous