Posting HTTP commands using C#

I

Isaac Martinez

Hello all,

I have to make a small app that will do the following.

1. Connect to a webserver and get a directory listing.
2. I have to download each file in the specified directory.
3. Once the file is downloaded, enter the data into a SQL2k database.
4. After the file is parsed, I have to delete the file.

I was able to successfully complete steps 1-3 using the
System.Net.WebClient class. Step #4 is somewhat difficult because there's
no file delete method in the WebClient class.

Using network monitor I was able to sniff out the HTTP command that would
allow file deletion.
----------------------------------------------------
DELETE filename.txt
HTTP/1.1
Accept-Language: en-us
Destroy: NoUndelete
Translate: f
User-Agent: Microsoft Data Access Internet Publishing Provider DAV 1.1
Host: 192.168.XXX.XXX
Content-Length: 0
Connection: Keep-Alive
----------------------------------------------------

My question is the following: Is there anyway to post HTTP commands using
the .Net Framework?

Thanks,
Isaac
 
M

Martin Honnen

Isaac said:
Using network monitor I was able to sniff out the HTTP command that would
allow file deletion.
----------------------------------------------------
DELETE filename.txt
HTTP/1.1
Accept-Language: en-us
Destroy: NoUndelete
Translate: f
User-Agent: Microsoft Data Access Internet Publishing Provider DAV 1.1
Host: 192.168.XXX.XXX
Content-Length: 0
Connection: Keep-Alive

Look at HttpWebRequest (in System.Net), it has a property called Method
that you can set to "DELETE". You usually create a HttpWebRequest with
HttpWebRequest httpRequest = (HttpWebRequest)
WebRequest.Create("http://www.example.com/dir/subdir/file.html");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top