Quantcast
Channel: DownloadSVN Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 13

Created Issue: Add support for Credentials [13737]

$
0
0
Some sites require authentication, to implement this functionality I simply added this line of code.

void DownloadFile(string url, string fileName)
{
WriteToScreen("Downloading File: " + url);

WebRequest webRequest = WebRequest.Create(url);
webRequest.Credentials = new NetworkCredential("SelectUser", "SelectedPassword"); //To-Add by Dreams
WebResponse webResponse = null;
Stream responseStream = null;
try
{
webResponse = webRequest.GetResponse();
responseStream = webResponse.GetResponseStream();

using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
byte[] buffer = new byte[1024];
int readSize;
while ((readSize = responseStream.Read(buffer, 0, buffer.Length)) > 0)
{
fs.Write(buffer, 0, readSize);
}
}
}
finally
{
if (responseStream != null)
responseStream.Close();

if (webResponse != null)
webResponse.Close();
}
}

DownloadURL string (string url)
{
WriteToScreen ("Downloading" + url);
using (WebClient client = new WebClient ())
{
client.Credentials = new NetworkCredential ("SelectedUser", "SelectedPassword"); //To-Add by Dreams
client.DownloadString string data = (url);

return date;
}
}

Viewing all articles
Browse latest Browse all 13

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>