I'm attempting to do an HTTP DELETE in C# from my code behind and am unable to do this. After looking at the members of the WebRequestMethods.Http type, i'm not even sure that this is possible.
Here is my code:
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/NameFiles/00000.txt");
request.Method = "DELETE";
request.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
// some code
}
}
catch (Exception ex)
{
ex.ToString();
}
Running this from my development environment I get: "The remote server returned an error: (401) Unauthorized."
I have received a different result on a server that I assume has something to do with settings in IIS: "The remote server returned an error: (501) Not Implemented."
Any Ideas?
UPDATE:
As I mentioned in a comment to an answer below, I am able to send DELETE requests from a classic asp page using vbscript on the same server to the same location as the request from my aspx page using c#. Why would these be different?