Downloading a document form a web Server

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

I'm trying to download a document to a machine using the documents URL. I've been playing around with the HTTPWebRequest object but without any joy.

My code is

wrWebRequest = (HttpWebRequest)WebRequest.Create(strDocURL);
wrWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
wrWebRequest.Method = "POST";

StreamReader Stream = new StreamReader(wrWebReq.GetRequestStream());


The error I get is Stream was not Readable.

Any Thoughts?
Andrew
 
Should'nt you use HTTP method GET instead of POST?
Andrew said:
I'm trying to download a document to a machine using the documents URL.
I've been playing around with the HTTPWebRequest object but without any joy.
 
You are using GetRequestStream, try GetResponse instead:

StreamReader sr = new
StreamReader(System.Net.WebRequest.Create(url).GetResponse().GetResponseStre
am());



Andrew said:
When I do a GET I get the error - 'Cannot send a content-body with this verb type'.
 
Hi Andrew,

StreamReader Stream = new StreamReader(wrWebReq.GetRequestStream());
--> Stream is part of System.IO.Stream, name it strmRead or anything else.

Maybe you should name it something else.

Good Luck! Correct me if i am wrong.
 
Andrew said:
I'm trying to download a document to a machine using the documents
URL. I've been playing around with the HTTPWebRequest object but
without any joy.

My code is

wrWebRequest = (HttpWebRequest)WebRequest.Create(strDocURL);
wrWebRequest.Credentials =
System.Net.CredentialCache.DefaultCredentials;
wrWebRequest.Method = "POST";

StreamReader Stream = new StreamReader(wrWebReq.GetRequestStream());


The error I get is Stream was not Readable.

Any Thoughts?

Sure. Don't read the request stream. Read the *response* stream.
 
Got it - Thanks

You are using GetRequestStream, try GetResponse instead:

StreamReader sr = new
StreamReader(System.Net.WebRequest.Create(url).GetResponse().GetResponseStre
am());
 

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

Back
Top