Explore My Other Channel for More Cool and Valuable Insights
π Youtube Learn Tech Tipsπ Tiktok
π Facebook:Below is sharing full source code how to read file with HttpWebResponse
/* *********************************************
* Developers: Zidane (huuvi168@gmail.com)
* Last Modified: 2015-11-12
* *********************************************/
public static string readFileOnInternet()
{
// used on each read operation
byte[] buf = new byte[1024];
// prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)WebRequest.Create
("https://googledrive.com/host/0Bw0wdOxjVlxfX0FrSmlXdm9pVm8");
// execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// we will read data via the response stream
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);
// make sure we read some data
if (count != 0)
{
// translate from bytes to ASCII text
tempString = Encoding.ASCII.GetString(buf, 0, count);
}
}
while (count > 0); // any more data to read?
// print out page source
return tempString;
}
Note
Using HttpWebRequest for Http WebRequestUsing Stream for get response stream
Thank you for reading this post. I hope you found it helpful and easy to follow. If you have any feedback or questions about
How to read file on Internet with C# with HttpWebResponse ,
please share them in the comments below. I would love to hear from you and discuss this topic further
✋✋✋✋
Webzone Tech Tips, all things Tech Tips for web development
- I am Zidane, See you next time soon ✋✋✋✋