Beruflich Dokumente
Kultur Dokumente
Client-Side Classes
WebClient Download Page
OpenHtml ("code.htm");
void DownloadPage()
{
WebRequest req = WebRequest.Create
("http://www.albahari.com/nutshell/code.html");
req.Proxy = null;
using (WebResponse res = req.GetResponse())
using (Stream rs = res.GetResponseStream())
using (FileStream fs = File.Create ("code_sync.html"))
rs.CopyTo (fs);
}
DownloadPage();
await DownloadPageAsync();
public MockHandler
(Func<HttpRequestMessage, HttpResponseMessage> responseGenerator)
{
_responseGenerator = responseGenerator;
}
public MockHandler
(Func<HttpRequestMessage, HttpResponseMessage> responseGenerator)
{
_responseGenerator = responseGenerator;
}
async Task CopyStreamWithProgressAsync (Stream input, Stream output, long total, IProgress<double> progress, CancellationToken t
{
const int IO_BUFFER_SIZE = 8 * 1024; // Optimal size depends on your scenario
// Expected size of input stream may be known from an HTTP header when reading from HTTP. Other streams may have their
// own protocol for pre-reporting expected size.
async Task DownloadFileAsync (string url, Stream destination, IProgress<double> progress, CancellationToken token)
{
var response = await client.GetAsync (url, HttpCompletionOption.ResponseHeadersRead, token);
if (!response.IsSuccessStatusCode)
throw new Exception (string.Format ("The request returned with HTTP status code {0}", response.StatusCode));
Exception handling
Code Listings
C# 8.0 in a Nutshell
C# 7.0 in a Nutshell
C# 6.0 in a Nutshell
Extras
Contact Authors