19 private class ProgressData
21 internal long BytesSent;
23 internal long TotalBytesToSend = -1
L;
25 internal long BytesReceived;
27 internal long TotalBytesToReceive = -1
L;
29 internal bool HasUploadPhase;
34 TotalBytesToSend = -1
L;
36 TotalBytesToReceive = -1
L;
37 HasUploadPhase =
false;
41 private class DownloadBitsState
45 internal Stream WriteStream;
47 internal byte[] InnerBuffer;
53 internal CompletionDelegate CompletionDelegate;
55 internal Stream ReadStream;
57 internal ScatterGatherBuffers SgBuffers;
59 internal long ContentLength;
67 internal bool Async => AsyncOp !=
null;
71 WriteStream = writeStream;
74 CompletionDelegate = completionDelegate;
82 if (ContentLength == -1 || ContentLength > 65536)
88 Length = ContentLength;
90 if (WriteStream ==
null)
92 if (ContentLength >
int.MaxValue)
96 SgBuffers =
new ScatterGatherBuffers(Length);
98 InnerBuffer =
new byte[(int)Length];
106 if (ReadStream ==
null || ReadStream ==
Stream.
Null)
108 DownloadBitsReadCallbackState(
this,
null);
112 ReadStream.BeginRead(InnerBuffer, Offset, (
int)Length - Offset, DownloadBitsReadCallback,
this);
116 if (ReadStream ==
null || ReadStream ==
Stream.
Null)
120 return ReadStream.Read(InnerBuffer, Offset, (
int)Length - Offset);
123 internal bool RetrieveBytes(ref
int bytesRetrieved)
125 if (bytesRetrieved > 0)
127 if (WriteStream !=
null)
129 WriteStream.
Write(InnerBuffer, 0, bytesRetrieved);
133 SgBuffers.Write(InnerBuffer, 0, bytesRetrieved);
137 Progress.BytesReceived += bytesRetrieved;
139 if (Offset != ContentLength)
144 ReadStream.
BeginRead(InnerBuffer, Offset, (
int)Length - Offset, DownloadBitsReadCallback,
this);
148 bytesRetrieved = ReadStream.
Read(InnerBuffer, Offset, (
int)Length - Offset);
155 if (
Progress.TotalBytesToReceive < 0)
161 if (ReadStream !=
null)
165 if (WriteStream !=
null)
169 else if (WriteStream ==
null)
171 byte[] array =
new byte[SgBuffers.Length];
172 if (SgBuffers.Length > 0)
174 BufferOffsetSize[] buffers = SgBuffers.GetBuffers();
176 foreach (BufferOffsetSize bufferOffsetSize
in buffers)
178 Buffer.
BlockCopy(bufferOffsetSize.Buffer, 0, array, num, bufferOffsetSize.Size);
179 num += bufferOffsetSize.Size;
187 internal void Close()
189 if (WriteStream !=
null)
193 if (ReadStream !=
null)
200 private class UploadBitsState
202 private int m_ChunkSize;
204 private int m_BufferWritePosition;
208 internal Stream WriteStream;
210 internal byte[] InnerBuffer;
212 internal byte[] Header;
214 internal byte[] Footer;
220 internal CompletionDelegate UploadCompletionDelegate;
222 internal CompletionDelegate DownloadCompletionDelegate;
224 internal Stream ReadStream;
226 internal long Length;
232 internal bool FileUpload => ReadStream !=
null;
234 internal bool Async => AsyncOp !=
null;
236 internal UploadBitsState(
WebRequest request,
Stream readStream,
byte[] buffer,
int chunkSize,
byte[] header,
byte[] footer, CompletionDelegate uploadCompletionDelegate, CompletionDelegate downloadCompletionDelegate,
AsyncOperation asyncOp, ProgressData progress,
WebClient webClient)
238 InnerBuffer = buffer;
239 m_ChunkSize = chunkSize;
240 m_BufferWritePosition = 0;
243 ReadStream = readStream;
246 UploadCompletionDelegate = uploadCompletionDelegate;
247 DownloadCompletionDelegate = downloadCompletionDelegate;
257 internal void SetRequestStream(
Stream writeStream)
259 WriteStream = writeStream;
273 WriteStream.
BeginWrite(array, 0, array.Length, UploadBitsWriteCallback,
this);
277 WriteStream.
Write(array, 0, array.Length);
281 internal bool WriteBytes()
293 if (InnerBuffer !=
null)
295 num3 = ReadStream.
Read(InnerBuffer, 0, InnerBuffer.Length);
302 if (InnerBuffer !=
null)
320 if (InnerBuffer ==
null)
325 if (m_ChunkSize != 0)
327 num2 = m_BufferWritePosition;
328 m_BufferWritePosition += m_ChunkSize;
330 if (m_BufferWritePosition >= InnerBuffer.Length)
332 num = InnerBuffer.Length - num2;
338 num = InnerBuffer.Length;
345 WriteStream.
BeginWrite(array, num2, num, UploadBitsWriteCallback,
this);
349 WriteStream.
Write(array, 0, num);
354 internal void Close()
356 if (WriteStream !=
null)
360 if (ReadStream !=
null)
367 private class WebClientWriteStream :
Stream 375 public override bool CanRead => m_stream.
CanRead;
377 public override bool CanSeek => m_stream.
CanSeek;
379 public override bool CanWrite => m_stream.
CanWrite;
381 public override bool CanTimeout => m_stream.
CanTimeout;
383 public override int ReadTimeout
395 public override int WriteTimeout
407 public override long Length => m_stream.
Length;
409 public override long Position
425 m_WebClient = webClient;
431 return m_stream.
BeginRead(buffer, offset, size, callback, state);
437 return m_stream.
BeginWrite(buffer, offset, size, callback, state);
440 protected override void Dispose(
bool disposing)
452 base.Dispose(disposing);
458 return m_stream.
EndRead(result);
466 public override void Flush()
471 public override int Read(
byte[] buffer,
int offset,
int count)
473 return m_stream.
Read(buffer, offset, count);
476 public override long Seek(
long offset,
SeekOrigin origin)
478 return m_stream.
Seek(offset, origin);
481 public override void SetLength(
long value)
486 public override void Write(
byte[] buffer,
int offset,
int count)
488 m_stream.
Write(buffer, offset, count);
492 private const int DefaultCopyBufferLength = 8192;
494 private const int DefaultDownloadBufferLength = 65536;
496 private const string DefaultUploadFileContentType =
"application/octet-stream";
498 private const string UploadFileContentType =
"multipart/form-data";
500 private const string UploadValuesContentType =
"application/x-www-form-urlencoded";
502 private Uri m_baseAddress;
516 private string m_Method;
518 private long m_ContentLength = -1
L;
520 private bool m_InitWebClientAsync;
522 private bool m_Cancelled;
524 private ProgressData m_Progress;
528 private bool m_ProxySet;
532 private int m_CallNesting;
561 [Obsolete(
"This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.",
true)]
572 [Obsolete(
"This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.",
true)]
606 if (!(m_baseAddress ==
null))
614 if (value ==
null || value.Length == 0)
616 m_baseAddress =
null;
622 m_baseAddress =
new Uri(value);
626 throw new ArgumentException(SR.GetString(
"net_webclient_invalid_baseaddress"),
"value", innerException);
638 return m_credentials;
642 m_credentials = value;
653 if (!(m_credentials is SystemNetworkCredential))
671 if (m_headers ==
null)
689 if (m_requestParameters ==
null)
693 return m_requestParameters;
697 m_requestParameters = value;
707 if (m_WebResponse !=
null)
723 ExceptionHelper.WebPermissionUnrestricted.Demand();
732 ExceptionHelper.WebPermissionUnrestricted.Demand();
744 return m_CachePolicy;
748 m_CachePolicy = value;
758 [Obsolete(
"This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.",
true)]
812 private void InitWebClientAsync()
814 if (!m_InitWebClientAsync)
816 openReadOperationCompleted = OpenReadOperationCompleted;
817 openWriteOperationCompleted = OpenWriteOperationCompleted;
818 downloadStringOperationCompleted = DownloadStringOperationCompleted;
819 downloadDataOperationCompleted = DownloadDataOperationCompleted;
820 downloadFileOperationCompleted = DownloadFileOperationCompleted;
821 uploadStringOperationCompleted = UploadStringOperationCompleted;
822 uploadDataOperationCompleted = UploadDataOperationCompleted;
823 uploadFileOperationCompleted = UploadFileOperationCompleted;
824 uploadValuesOperationCompleted = UploadValuesOperationCompleted;
825 reportDownloadProgressChanged = ReportDownloadProgressChanged;
826 reportUploadProgressChanged = ReportUploadProgressChanged;
827 m_Progress =
new ProgressData();
828 m_InitWebClientAsync =
true;
832 private void ClearWebClientState()
836 CompleteWebClientState();
837 throw new NotSupportedException(SR.GetString(
"net_webclient_no_concurrent_io_allowed"));
839 m_ContentLength = -1
L;
840 m_WebResponse =
null;
844 if (m_Progress !=
null)
850 private void CompleteWebClientState()
857 [Obsolete(
"This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.",
true)]
869 CopyHeadersTo(webRequest);
874 if (m_Method !=
null)
876 webRequest.
Method = m_Method;
878 if (m_ContentLength != -1)
884 webRequest.
Proxy = m_Proxy;
886 if (m_CachePolicy !=
null)
933 Logging.Enter(Logging.Web,
this,
"DownloadData", address);
939 ClearWebClientState();
943 array = DownloadDataInternal(address, out
WebRequest _);
946 Logging.Exit(Logging.Web,
this,
"DownloadData", array);
952 CompleteWebClientState();
956 private byte[] DownloadDataInternal(
Uri address, out
WebRequest request)
960 Logging.Enter(Logging.Web,
this,
"DownloadData", address);
966 return DownloadBits(request,
null,
null,
null);
971 if (ex2 is
ThreadAbortException || ex2 is StackOverflowException || ex2 is OutOfMemoryException)
977 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
979 AbortRequest(request);
1011 Logging.Enter(Logging.Web,
this,
"DownloadFile", address +
", " + fileName);
1013 if (address ==
null)
1017 if (fileName ==
null)
1024 ClearWebClientState();
1029 DownloadBits(request, fileStream,
null,
null);
1041 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
1043 AbortRequest(request);
1048 if (fileStream !=
null)
1057 CompleteWebClientState();
1061 Logging.Exit(Logging.Web,
this,
"DownloadFile",
"");
1072 if (address ==
null)
1088 Logging.Enter(Logging.Web,
this,
"OpenRead", address);
1090 if (address ==
null)
1095 ClearWebClientState();
1102 Logging.Exit(Logging.Web,
this,
"OpenRead", responseStream);
1104 return responseStream;
1115 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
1117 AbortRequest(request);
1122 CompleteWebClientState();
1133 if (address ==
null)
1137 return OpenWrite(GetUri(address),
null);
1158 if (address ==
null)
1162 return OpenWrite(GetUri(address), method);
1175 Logging.Enter(Logging.Web,
this,
"OpenWrite", address +
", " + method);
1177 if (address ==
null)
1183 method = MapToDefaultMethod(address);
1186 ClearWebClientState();
1190 webRequest = (m_WebRequest =
GetWebRequest(GetUri(address)));
1191 WebClientWriteStream webClientWriteStream =
new WebClientWriteStream(webRequest.
GetRequestStream(), webRequest,
this);
1194 Logging.Exit(Logging.Web,
this,
"OpenWrite", webClientWriteStream);
1196 return webClientWriteStream;
1207 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
1209 AbortRequest(webRequest);
1214 CompleteWebClientState();
1227 if (address ==
null)
1231 return UploadData(GetUri(address),
null, data);
1254 public byte[]
UploadData(
string address,
string method,
byte[] data)
1256 if (address ==
null)
1260 return UploadData(GetUri(address), method, data);
1275 Logging.Enter(Logging.Web,
this,
"UploadData", address +
", " + method);
1277 if (address ==
null)
1287 method = MapToDefaultMethod(address);
1289 ClearWebClientState();
1293 byte[] array = UploadDataInternal(address, method, data, out request);
1296 Logging.Exit(Logging.Web,
this,
"UploadData", array);
1302 CompleteWebClientState();
1306 private byte[] UploadDataInternal(
Uri address,
string method,
byte[] data, out
WebRequest request)
1312 m_ContentLength = data.Length;
1314 UploadBits(request,
null, data, 0,
null,
null,
null,
null,
null);
1315 return DownloadBits(request,
null,
null,
null);
1326 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
1328 AbortRequest(request);
1333 private void OpenFileInternal(
bool needsHeaderAndBoundary,
string fileName, ref
FileStream fs, ref
byte[] buffer, ref
byte[] formHeaderBytes, ref
byte[] boundaryBytes)
1336 if (m_headers ==
null)
1338 m_headers =
new WebHeaderCollection(WebHeaderCollectionType.WebRequest);
1340 string text = m_headers[
"Content-Type"];
1345 throw new WebException(SR.GetString(
"net_webclient_Multipart"));
1350 text =
"application/octet-stream";
1354 m_ContentLength = -1
L;
1357 if (needsHeaderAndBoundary)
1360 m_headers[
"Content-Type"] =
"multipart/form-data; boundary=" + text2;
1361 string s =
"--" + text2 +
"\r\nContent-Disposition: form-data; name=\"file\"; filename=\"" +
Path.
GetFileName(fileName) +
"\"\r\nContent-Type: " + text +
"\r\n\r\n";
1367 formHeaderBytes =
new byte[0];
1368 boundaryBytes =
new byte[0];
1372 m_ContentLength = fs.Length + formHeaderBytes.Length + boundaryBytes.Length;
1373 num = (int)Math.Min(8192L, fs.Length);
1378 m_headers[
"Content-Type"] = text;
1379 formHeaderBytes =
null;
1380 boundaryBytes =
null;
1383 m_ContentLength = fs.Length;
1384 num = (int)Math.Min(8192L, fs.Length);
1387 buffer =
new byte[num];
1399 if (address ==
null)
1403 return UploadFile(GetUri(address), fileName);
1426 public byte[]
UploadFile(
string address,
string method,
string fileName)
1428 return UploadFile(GetUri(address), method, fileName);
1443 Logging.Enter(Logging.Web,
this,
"UploadFile", address +
", " + method);
1445 if (address ==
null)
1449 if (fileName ==
null)
1455 method = MapToDefaultMethod(address);
1459 ClearWebClientState();
1463 byte[] formHeaderBytes =
null;
1464 byte[] boundaryBytes =
null;
1465 byte[] buffer =
null;
1466 Uri uri = GetUri(address);
1468 OpenFileInternal(needsHeaderAndBoundary, fileName, ref fs, ref buffer, ref formHeaderBytes, ref boundaryBytes);
1470 UploadBits(request, fs, buffer, 0, formHeaderBytes, boundaryBytes,
null,
null,
null);
1471 byte[] array = DownloadBits(request,
null,
null,
null);
1474 Logging.Exit(Logging.Web,
this,
"UploadFile", array);
1492 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
1494 AbortRequest(request);
1499 CompleteWebClientState();
1505 if (m_headers ==
null)
1509 string text = m_headers[
"Content-Type"];
1510 if (text !=
null &&
string.Compare(text,
"application/x-www-form-urlencoded",
StringComparison.OrdinalIgnoreCase) != 0)
1512 throw new WebException(SR.GetString(
"net_webclient_ContentType"));
1514 m_headers[
"Content-Type"] =
"application/x-www-form-urlencoded";
1515 string value =
string.Empty;
1517 string[] allKeys = data.AllKeys;
1518 foreach (
string text2
in allKeys)
1520 stringBuilder.
Append(value);
1521 stringBuilder.
Append(UrlEncode(text2));
1522 stringBuilder.
Append(
"=");
1523 stringBuilder.
Append(UrlEncode(data[text2]));
1527 m_ContentLength = bytes.Length;
1540 if (address ==
null)
1569 if (address ==
null)
1588 Logging.Enter(Logging.Web,
this,
"UploadValues", address +
", " + method);
1590 if (address ==
null)
1600 method = MapToDefaultMethod(address);
1603 ClearWebClientState();
1606 byte[] buffer = UploadValuesInternal(data);
1609 UploadBits(request,
null, buffer, 0,
null,
null,
null,
null,
null);
1610 byte[] result = DownloadBits(request,
null,
null,
null);
1613 Logging.Exit(Logging.Web,
this,
"UploadValues", address +
", " + method);
1626 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
1628 AbortRequest(request);
1633 CompleteWebClientState();
1645 if (address ==
null)
1673 if (address ==
null)
1692 Logging.Enter(Logging.Web,
this,
"UploadString", address +
", " + method);
1694 if (address ==
null)
1704 method = MapToDefaultMethod(address);
1706 ClearWebClientState();
1711 byte[] data2 = UploadDataInternal(address, method, bytes, out request);
1712 string stringUsingEncoding = GetStringUsingEncoding(request, data2);
1715 Logging.Exit(Logging.Web,
this,
"UploadString", stringUsingEncoding);
1717 return stringUsingEncoding;
1721 CompleteWebClientState();
1733 if (address ==
null)
1750 Logging.Enter(Logging.Web,
this,
"DownloadString", address);
1752 if (address ==
null)
1756 ClearWebClientState();
1760 byte[] data = DownloadDataInternal(address, out request);
1761 string stringUsingEncoding = GetStringUsingEncoding(request, data);
1764 Logging.Exit(Logging.Web,
this,
"DownloadString", stringUsingEncoding);
1766 return stringUsingEncoding;
1770 CompleteWebClientState();
1774 private static void AbortRequest(
WebRequest request)
1789 private void CopyHeadersTo(WebRequest request)
1791 if (m_headers !=
null && request is HttpWebRequest)
1793 string text = m_headers[
"Accept"];
1794 string text2 = m_headers[
"Connection"];
1795 string text3 = m_headers[
"Content-Type"];
1796 string text4 = m_headers[
"Expect"];
1797 string text5 = m_headers[
"Referer"];
1798 string text6 = m_headers[
"User-Agent"];
1799 string text7 = m_headers[
"Host"];
1800 m_headers.RemoveInternal(
"Accept");
1801 m_headers.RemoveInternal(
"Connection");
1802 m_headers.RemoveInternal(
"Content-Type");
1803 m_headers.RemoveInternal(
"Expect");
1804 m_headers.RemoveInternal(
"Referer");
1805 m_headers.RemoveInternal(
"User-Agent");
1806 m_headers.RemoveInternal(
"Host");
1807 request.Headers = m_headers;
1808 if (text !=
null && text.Length > 0)
1810 ((HttpWebRequest)request).Accept = text;
1812 if (text2 !=
null && text2.Length > 0)
1814 ((HttpWebRequest)request).Connection = text2;
1816 if (text3 !=
null && text3.Length > 0)
1818 ((HttpWebRequest)request).ContentType = text3;
1820 if (text4 !=
null && text4.Length > 0)
1822 ((HttpWebRequest)request).Expect = text4;
1824 if (text5 !=
null && text5.Length > 0)
1826 ((HttpWebRequest)request).Referer = text5;
1828 if (text6 !=
null && text6.Length > 0)
1830 ((HttpWebRequest)request).UserAgent = text6;
1832 if (!
string.IsNullOrEmpty(text7))
1834 ((HttpWebRequest)request).Host = text7;
1839 private Uri GetUri(
string path)
1842 if (m_baseAddress !=
null)
1844 if (!Uri.TryCreate(m_baseAddress, path, out result))
1849 else if (!Uri.TryCreate(path,
UriKind.Absolute, out result))
1853 return GetUri(result);
1856 private Uri GetUri(Uri address)
1858 if (address ==
null)
1860 throw new ArgumentNullException(
"address");
1862 Uri result = address;
1863 if (!address.IsAbsoluteUri && m_baseAddress !=
null && !Uri.TryCreate(m_baseAddress, address, out result))
1867 if ((result.Query ==
null || result.Query ==
string.Empty) && m_requestParameters !=
null)
1870 string str =
string.Empty;
1871 for (
int i = 0; i < m_requestParameters.
Count; i++)
1873 stringBuilder.
Append(str + m_requestParameters.
AllKeys[i] +
"=" + m_requestParameters[i]);
1876 UriBuilder uriBuilder =
new UriBuilder(result);
1877 uriBuilder.Query = stringBuilder.
ToString();
1878 result = uriBuilder.Uri;
1883 private static void DownloadBitsResponseCallback(IAsyncResult result)
1885 DownloadBitsState downloadBitsState = (DownloadBitsState)result.AsyncState;
1886 WebRequest request = downloadBitsState.Request;
1887 Exception ex =
null;
1890 WebResponse webResponse = downloadBitsState.WebClient.GetWebResponse(request, result);
1891 downloadBitsState.WebClient.m_WebResponse = webResponse;
1892 downloadBitsState.SetResponse(webResponse);
1894 catch (Exception ex2)
1896 if (ex2 is
ThreadAbortException || ex2 is StackOverflowException || ex2 is OutOfMemoryException)
1903 ex =
new WebException(SR.GetString(
"net_webclient"), ex2);
1905 AbortRequest(request);
1906 if (downloadBitsState !=
null && downloadBitsState.WriteStream !=
null)
1908 downloadBitsState.WriteStream.Close();
1915 downloadBitsState.CompletionDelegate(
null, ex, downloadBitsState.AsyncOp);
1920 private static void DownloadBitsReadCallback(IAsyncResult result)
1922 DownloadBitsState state = (DownloadBitsState)result.AsyncState;
1923 DownloadBitsReadCallbackState(state, result);
1926 private static void DownloadBitsReadCallbackState(DownloadBitsState state, IAsyncResult result)
1928 Stream readStream = state.ReadStream;
1929 Exception ex =
null;
1933 int bytesRetrieved = 0;
1934 if (readStream !=
null && readStream !=
Stream.
Null)
1936 bytesRetrieved = readStream.
EndRead(result);
1938 flag = state.RetrieveBytes(ref bytesRetrieved);
1940 catch (Exception ex2)
1943 if (ex2 is
ThreadAbortException || ex2 is StackOverflowException || ex2 is OutOfMemoryException)
1948 state.InnerBuffer =
null;
1951 ex =
new WebException(SR.GetString(
"net_webclient"), ex2);
1953 AbortRequest(state.Request);
1954 if (state !=
null && state.WriteStream !=
null)
1956 state.WriteStream.Close();
1967 state.CompletionDelegate(state.InnerBuffer, ex, state.AsyncOp);
1972 private byte[] DownloadBits(WebRequest request,
Stream writeStream, CompletionDelegate completionDelegate,
AsyncOperation asyncOp)
1974 WebResponse webResponse =
null;
1975 DownloadBitsState downloadBitsState =
new DownloadBitsState(request, writeStream, completionDelegate, asyncOp, m_Progress,
this);
1976 if (downloadBitsState.Async)
1978 request.BeginGetResponse(DownloadBitsResponseCallback, downloadBitsState);
1981 int bytesRetrieved = downloadBitsState.SetResponse(m_WebResponse = GetWebResponse(request));
1982 while (!downloadBitsState.RetrieveBytes(ref bytesRetrieved))
1985 downloadBitsState.Close();
1986 return downloadBitsState.InnerBuffer;
1989 private static void UploadBitsRequestCallback(IAsyncResult result)
1991 UploadBitsState uploadBitsState = (UploadBitsState)result.AsyncState;
1992 WebRequest request = uploadBitsState.Request;
1993 Exception ex =
null;
1996 Stream requestStream = request.EndGetRequestStream(result);
1997 uploadBitsState.SetRequestStream(requestStream);
1999 catch (Exception ex2)
2001 if (ex2 is
ThreadAbortException || ex2 is StackOverflowException || ex2 is OutOfMemoryException)
2008 ex =
new WebException(SR.GetString(
"net_webclient"), ex2);
2010 AbortRequest(request);
2011 if (uploadBitsState !=
null && uploadBitsState.ReadStream !=
null)
2013 uploadBitsState.ReadStream.Close();
2020 uploadBitsState.UploadCompletionDelegate(
null, ex, uploadBitsState);
2025 private static void UploadBitsWriteCallback(IAsyncResult result)
2027 UploadBitsState uploadBitsState = (UploadBitsState)result.AsyncState;
2028 Stream writeStream = uploadBitsState.WriteStream;
2029 Exception ex =
null;
2034 flag = uploadBitsState.WriteBytes();
2036 catch (Exception ex2)
2039 if (ex2 is
ThreadAbortException || ex2 is StackOverflowException || ex2 is OutOfMemoryException)
2046 ex =
new WebException(SR.GetString(
"net_webclient"), ex2);
2048 AbortRequest(uploadBitsState.Request);
2049 if (uploadBitsState !=
null && uploadBitsState.ReadStream !=
null)
2051 uploadBitsState.ReadStream.Close();
2060 uploadBitsState.Close();
2062 uploadBitsState.UploadCompletionDelegate(
null, ex, uploadBitsState);
2067 private void UploadBits(WebRequest request,
Stream readStream,
byte[] buffer,
int chunkSize,
byte[] header,
byte[] footer, CompletionDelegate uploadCompletionDelegate, CompletionDelegate downloadCompletionDelegate,
AsyncOperation asyncOp)
2069 if (request.RequestUri.Scheme == Uri.UriSchemeFile)
2071 header = (footer =
null);
2073 UploadBitsState uploadBitsState =
new UploadBitsState(request, readStream, buffer, chunkSize, header, footer, uploadCompletionDelegate, downloadCompletionDelegate, asyncOp, m_Progress,
this);
2074 if (uploadBitsState.Async)
2076 request.BeginGetRequestStream(UploadBitsRequestCallback, uploadBitsState);
2079 Stream requestStream = request.GetRequestStream();
2080 uploadBitsState.SetRequestStream(requestStream);
2081 while (!uploadBitsState.WriteBytes())
2084 uploadBitsState.Close();
2087 private bool ByteArrayHasPrefix(
byte[] prefix,
byte[] byteArray)
2089 if (prefix ==
null || byteArray ==
null || prefix.Length > byteArray.Length)
2093 for (
int i = 0; i < prefix.Length; i++)
2095 if (prefix[i] != byteArray[i])
2103 private string GetStringUsingEncoding(WebRequest request,
byte[] data)
2110 text = request.ContentType;
2112 catch (NotImplementedException)
2116 catch (NotSupportedException)
2123 string[] array = text.Split(
';',
'=',
' ');
2125 string[] array2 = array;
2126 foreach (
string text2
in array2)
2128 if (text2 ==
"charset")
2138 catch (ArgumentException)
2147 if (encoding ==
null)
2156 for (
int j = 0; j < array3.Length; j++)
2159 if (ByteArrayHasPrefix(preamble, data))
2161 encoding = array3[j];
2162 num = preamble.Length;
2167 if (encoding ==
null)
2174 num = (ByteArrayHasPrefix(preamble2, data) ? preamble2.Length : 0);
2176 return encoding.
GetString(data, num, data.Length - num);
2179 private string MapToDefaultMethod(Uri address)
2181 Uri uri = (address.IsAbsoluteUri || !(m_baseAddress !=
null)) ? address :
new Uri(m_baseAddress, address);
2189 private static string UrlEncode(
string str)
2198 private static string UrlEncode(
string str,
Encoding e)
2207 private static byte[] UrlEncodeToBytes(
string str,
Encoding e)
2214 return UrlEncodeBytesToBytesInternal(bytes, 0, bytes.Length, alwaysCreateReturnValue:
false);
2217 private static byte[] UrlEncodeBytesToBytesInternal(
byte[] bytes,
int offset,
int count,
bool alwaysCreateReturnValue)
2221 for (
int i = 0; i < count; i++)
2223 char c = (char)bytes[offset + i];
2228 else if (!IsSafe(c))
2233 if (!alwaysCreateReturnValue && num == 0 && num2 == 0)
2237 byte[] array =
new byte[count + num2 * 2];
2239 for (
int j = 0; j < count; j++)
2241 byte b = bytes[offset + j];
2254 array[num3++] = (byte)IntToHex((b >> 4) & 0xF);
2255 array[num3++] = (byte)IntToHex(b & 0xF);
2260 private static char IntToHex(
int n)
2264 return (
char)(n + 48);
2266 return (
char)(n - 10 + 97);
2269 private static bool IsSafe(
char ch)
2271 if ((ch >=
'a' && ch <=
'z') || (ch >=
'A' && ch <=
'Z') || (ch >=
'0' && ch <=
'9'))
2295 CompleteWebClientState();
2300 private bool AnotherCallInProgress(
int callNesting)
2302 return callNesting > 1;
2309 if (this.OpenReadCompleted !=
null)
2311 this.OpenReadCompleted(
this, e);
2315 private void OpenReadOperationCompleted(
object arg)
2320 private void OpenReadAsyncCallback(
IAsyncResult result)
2322 LazyAsyncResult lazyAsyncResult = (LazyAsyncResult)result;
2324 WebRequest request = (WebRequest)lazyAsyncResult.AsyncObject;
2329 result2 = (m_WebResponse = GetWebResponse(request, result)).GetResponseStream();
2331 catch (Exception ex)
2340 exception =
new WebException(SR.GetString(
"net_webclient"), ex);
2343 OpenReadCompletedEventArgs eventArgs =
new OpenReadCompletedEventArgs(result2, exception, m_Cancelled, asyncOperation.
UserSuppliedState);
2344 InvokeOperationCompleted(asyncOperation, openReadOperationCompleted, eventArgs);
2351 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2354 OpenReadAsync(address,
null);
2362 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2367 Logging.Enter(Logging.Web,
this,
"OpenReadAsync", address);
2369 if (address ==
null)
2373 InitWebClientAsync();
2374 ClearWebClientState();
2378 (m_WebRequest = GetWebRequest(GetUri(address))).BeginGetResponse(OpenReadAsyncCallback, asyncOperation);
2389 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
2392 InvokeOperationCompleted(asyncOperation, openReadOperationCompleted, eventArgs);
2396 Logging.Exit(Logging.Web,
this,
"OpenReadAsync",
null);
2404 if (this.OpenWriteCompleted !=
null)
2406 this.OpenWriteCompleted(
this, e);
2410 private void OpenWriteOperationCompleted(
object arg)
2415 private void OpenWriteAsyncCallback(
IAsyncResult result)
2417 LazyAsyncResult lazyAsyncResult = (LazyAsyncResult)result;
2419 WebRequest webRequest = (WebRequest)lazyAsyncResult.AsyncObject;
2420 WebClientWriteStream result2 =
null;
2424 result2 =
new WebClientWriteStream(webRequest.EndGetRequestStream(result), webRequest,
this);
2426 catch (Exception ex)
2435 exception =
new WebException(SR.GetString(
"net_webclient"), ex);
2438 OpenWriteCompletedEventArgs eventArgs =
new OpenWriteCompletedEventArgs(result2, exception, m_Cancelled, asyncOperation.
UserSuppliedState);
2439 InvokeOperationCompleted(asyncOperation, openWriteOperationCompleted, eventArgs);
2445 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2448 OpenWriteAsync(address,
null,
null);
2455 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2458 OpenWriteAsync(address, method,
null);
2467 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2472 Logging.Enter(Logging.Web,
this,
"OpenWriteAsync", address +
", " + method);
2474 if (address ==
null)
2480 method = MapToDefaultMethod(address);
2482 InitWebClientAsync();
2483 ClearWebClientState();
2488 (m_WebRequest = GetWebRequest(GetUri(address))).BeginGetRequestStream(OpenWriteAsyncCallback, asyncOperation);
2499 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
2502 InvokeOperationCompleted(asyncOperation, openWriteOperationCompleted, eventArgs);
2506 Logging.Exit(Logging.Web,
this,
"OpenWriteAsync",
null);
2514 if (this.DownloadStringCompleted !=
null)
2516 this.DownloadStringCompleted(
this, e);
2520 private void DownloadStringOperationCompleted(
object arg)
2525 private void DownloadStringAsyncCallback(
byte[] returnBytes,
Exception exception,
object state)
2528 string result =
null;
2531 if (returnBytes !=
null)
2533 result = GetStringUsingEncoding(m_WebRequest, returnBytes);
2536 catch (Exception ex)
2544 DownloadStringCompletedEventArgs eventArgs =
new DownloadStringCompletedEventArgs(result, exception, m_Cancelled, asyncOperation.
UserSuppliedState);
2545 InvokeOperationCompleted(asyncOperation, downloadStringOperationCompleted, eventArgs);
2552 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2555 DownloadStringAsync(address,
null);
2563 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2568 Logging.Enter(Logging.Web,
this,
"DownloadStringAsync", address);
2570 if (address ==
null)
2574 InitWebClientAsync();
2575 ClearWebClientState();
2579 DownloadBits(m_WebRequest = GetWebRequest(GetUri(address)),
null, DownloadStringAsyncCallback, asyncOperation);
2590 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
2592 DownloadStringAsyncCallback(
null, ex2, asyncOperation);
2596 Logging.Exit(Logging.Web,
this,
"DownloadStringAsync",
"");
2604 if (this.DownloadDataCompleted !=
null)
2606 this.DownloadDataCompleted(
this, e);
2610 private void DownloadDataOperationCompleted(
object arg)
2615 private void DownloadDataAsyncCallback(
byte[] returnBytes,
Exception exception,
object state)
2618 DownloadDataCompletedEventArgs eventArgs =
new DownloadDataCompletedEventArgs(returnBytes, exception, m_Cancelled, asyncOperation.
UserSuppliedState);
2619 InvokeOperationCompleted(asyncOperation, downloadDataOperationCompleted, eventArgs);
2626 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2629 DownloadDataAsync(address,
null);
2637 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2642 Logging.Enter(Logging.Web,
this,
"DownloadDataAsync", address);
2644 if (address ==
null)
2648 InitWebClientAsync();
2649 ClearWebClientState();
2653 DownloadBits(m_WebRequest = GetWebRequest(GetUri(address)),
null, DownloadDataAsyncCallback, asyncOperation);
2664 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
2666 DownloadDataAsyncCallback(
null, ex2, asyncOperation);
2670 Logging.Exit(Logging.Web,
this,
"DownloadDataAsync",
null);
2678 if (this.DownloadFileCompleted !=
null)
2680 this.DownloadFileCompleted(
this, e);
2684 private void DownloadFileOperationCompleted(
object arg)
2689 private void DownloadFileAsyncCallback(
byte[] returnBytes,
Exception exception,
object state)
2693 InvokeOperationCompleted(asyncOperation, downloadFileOperationCompleted, eventArgs);
2702 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2705 DownloadFileAsync(address, fileName,
null);
2715 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2720 Logging.Enter(Logging.Web,
this,
"DownloadFileAsync", address);
2722 if (address ==
null)
2726 if (fileName ==
null)
2731 InitWebClientAsync();
2732 ClearWebClientState();
2737 DownloadBits(m_WebRequest = GetWebRequest(GetUri(address)), fileStream, DownloadFileAsyncCallback, asyncOperation);
2746 fileStream?.
Close();
2749 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
2751 DownloadFileAsyncCallback(
null, ex2, asyncOperation);
2755 Logging.Exit(Logging.Web,
this,
"DownloadFileAsync",
null);
2763 if (this.UploadStringCompleted !=
null)
2765 this.UploadStringCompleted(
this, e);
2769 private void UploadStringOperationCompleted(
object arg)
2774 private void StartDownloadAsync(UploadBitsState state)
2778 DownloadBits(state.Request,
null, state.DownloadCompletionDelegate, state.AsyncOp);
2780 catch (Exception ex)
2783 if (ex2 is
ThreadAbortException || ex2 is StackOverflowException || ex2 is OutOfMemoryException)
2789 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
2791 state.DownloadCompletionDelegate(
null, ex2, state.AsyncOp);
2795 private void UploadStringAsyncWriteCallback(
byte[] returnBytes, Exception exception,
object state)
2797 UploadBitsState uploadBitsState = (UploadBitsState)state;
2798 if (exception !=
null)
2800 UploadStringCompletedEventArgs eventArgs =
new UploadStringCompletedEventArgs(
null, exception, m_Cancelled, uploadBitsState.AsyncOp.UserSuppliedState);
2801 InvokeOperationCompleted(uploadBitsState.AsyncOp, uploadStringOperationCompleted, eventArgs);
2805 StartDownloadAsync(uploadBitsState);
2809 private void UploadStringAsyncReadCallback(
byte[] returnBytes, Exception exception,
object state)
2812 string result =
null;
2815 if (returnBytes !=
null)
2817 result = GetStringUsingEncoding(m_WebRequest, returnBytes);
2820 catch (Exception ex)
2828 UploadStringCompletedEventArgs eventArgs =
new UploadStringCompletedEventArgs(result, exception, m_Cancelled, asyncOperation.
UserSuppliedState);
2829 InvokeOperationCompleted(asyncOperation, uploadStringOperationCompleted, eventArgs);
2839 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2842 UploadStringAsync(address,
null, data,
null);
2852 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2855 UploadStringAsync(address, method, data,
null);
2866 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2871 Logging.Enter(Logging.Web,
this,
"UploadStringAsync", address);
2873 if (address ==
null)
2883 method = MapToDefaultMethod(address);
2885 InitWebClientAsync();
2886 ClearWebClientState();
2892 m_ContentLength = bytes.Length;
2893 UploadBits(m_WebRequest = GetWebRequest(GetUri(address)),
null, bytes, 0,
null,
null, UploadStringAsyncWriteCallback, UploadStringAsyncReadCallback, asyncOperation);
2904 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
2907 InvokeOperationCompleted(asyncOperation, uploadStringOperationCompleted, eventArgs);
2911 Logging.Exit(Logging.Web,
this,
"UploadStringAsync",
null);
2919 if (this.UploadDataCompleted !=
null)
2921 this.UploadDataCompleted(
this, e);
2925 private void UploadDataOperationCompleted(
object arg)
2930 private void UploadDataAsyncWriteCallback(
byte[] returnBytes,
Exception exception,
object state)
2932 UploadBitsState uploadBitsState = (UploadBitsState)state;
2933 if (exception !=
null)
2935 UploadDataCompletedEventArgs eventArgs =
new UploadDataCompletedEventArgs(returnBytes, exception, m_Cancelled, uploadBitsState.AsyncOp.UserSuppliedState);
2936 InvokeOperationCompleted(uploadBitsState.AsyncOp, uploadDataOperationCompleted, eventArgs);
2940 StartDownloadAsync(uploadBitsState);
2944 private void UploadDataAsyncReadCallback(
byte[] returnBytes, Exception exception,
object state)
2947 UploadDataCompletedEventArgs eventArgs =
new UploadDataCompletedEventArgs(returnBytes, exception, m_Cancelled, asyncOperation.
UserSuppliedState);
2948 InvokeOperationCompleted(asyncOperation, uploadDataOperationCompleted, eventArgs);
2956 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2959 UploadDataAsync(address,
null, data,
null);
2968 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2971 UploadDataAsync(address, method, data,
null);
2981 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2986 Logging.Enter(Logging.Web,
this,
"UploadDataAsync", address +
", " + method);
2988 if (address ==
null)
2998 method = MapToDefaultMethod(address);
3000 InitWebClientAsync();
3001 ClearWebClientState();
3007 m_ContentLength = data.Length;
3008 WebRequest request = m_WebRequest = GetWebRequest(GetUri(address));
3009 if (this.UploadProgressChanged !=
null)
3011 chunkSize = (int)
Math.
Min(8192
L, data.Length);
3013 UploadBits(request,
null, data, chunkSize,
null,
null, UploadDataAsyncWriteCallback, UploadDataAsyncReadCallback, asyncOperation);
3024 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
3027 InvokeOperationCompleted(asyncOperation, uploadDataOperationCompleted, eventArgs);
3031 Logging.Exit(Logging.Web,
this,
"UploadDataAsync",
null);
3039 if (this.UploadFileCompleted !=
null)
3041 this.UploadFileCompleted(
this, e);
3045 private void UploadFileOperationCompleted(
object arg)
3050 private void UploadFileAsyncWriteCallback(
byte[] returnBytes,
Exception exception,
object state)
3052 UploadBitsState uploadBitsState = (UploadBitsState)state;
3053 if (exception !=
null)
3055 UploadFileCompletedEventArgs eventArgs =
new UploadFileCompletedEventArgs(returnBytes, exception, m_Cancelled, uploadBitsState.AsyncOp.UserSuppliedState);
3056 InvokeOperationCompleted(uploadBitsState.AsyncOp, uploadFileOperationCompleted, eventArgs);
3060 StartDownloadAsync(uploadBitsState);
3064 private void UploadFileAsyncReadCallback(
byte[] returnBytes, Exception exception,
object state)
3067 UploadFileCompletedEventArgs eventArgs =
new UploadFileCompletedEventArgs(returnBytes, exception, m_Cancelled, asyncOperation.
UserSuppliedState);
3068 InvokeOperationCompleted(asyncOperation, uploadFileOperationCompleted, eventArgs);
3077 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3080 UploadFileAsync(address,
null, fileName,
null);
3090 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3093 UploadFileAsync(address, method, fileName,
null);
3104 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3109 Logging.Enter(Logging.Web,
this,
"UploadFileAsync", address +
", " + method);
3111 if (address ==
null)
3115 if (fileName ==
null)
3121 method = MapToDefaultMethod(address);
3123 InitWebClientAsync();
3124 ClearWebClientState();
3130 byte[] formHeaderBytes =
null;
3131 byte[] boundaryBytes =
null;
3132 byte[] buffer =
null;
3133 Uri uri = GetUri(address);
3135 OpenFileInternal(needsHeaderAndBoundary, fileName, ref fs, ref buffer, ref formHeaderBytes, ref boundaryBytes);
3136 UploadBits(m_WebRequest = GetWebRequest(uri), fs, buffer, 0, formHeaderBytes, boundaryBytes, UploadFileAsyncWriteCallback, UploadFileAsyncReadCallback, asyncOperation);
3148 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
3151 InvokeOperationCompleted(asyncOperation, uploadFileOperationCompleted, eventArgs);
3155 Logging.Exit(Logging.Web,
this,
"UploadFileAsync",
null);
3163 if (this.UploadValuesCompleted !=
null)
3165 this.UploadValuesCompleted(
this, e);
3169 private void UploadValuesOperationCompleted(
object arg)
3174 private void UploadValuesAsyncWriteCallback(
byte[] returnBytes,
Exception exception,
object state)
3176 UploadBitsState uploadBitsState = (UploadBitsState)state;
3177 if (exception !=
null)
3179 UploadValuesCompletedEventArgs eventArgs =
new UploadValuesCompletedEventArgs(returnBytes, exception, m_Cancelled, uploadBitsState.AsyncOp.UserSuppliedState);
3180 InvokeOperationCompleted(uploadBitsState.AsyncOp, uploadValuesOperationCompleted, eventArgs);
3184 StartDownloadAsync(uploadBitsState);
3188 private void UploadValuesAsyncReadCallback(
byte[] returnBytes, Exception exception,
object state)
3191 UploadValuesCompletedEventArgs eventArgs =
new UploadValuesCompletedEventArgs(returnBytes, exception, m_Cancelled, asyncOperation.
UserSuppliedState);
3192 InvokeOperationCompleted(asyncOperation, uploadValuesOperationCompleted, eventArgs);
3200 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3203 UploadValuesAsync(address,
null, data,
null);
3213 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3216 UploadValuesAsync(address, method, data,
null);
3227 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3232 Logging.Enter(Logging.Web,
this,
"UploadValuesAsync", address +
", " + method);
3234 if (address ==
null)
3244 method = MapToDefaultMethod(address);
3246 InitWebClientAsync();
3247 ClearWebClientState();
3252 byte[] array = UploadValuesInternal(data);
3254 WebRequest request = m_WebRequest = GetWebRequest(GetUri(address));
3255 if (this.UploadProgressChanged !=
null)
3257 chunkSize = (int)
Math.
Min(8192
L, array.Length);
3259 UploadBits(request,
null, array, chunkSize,
null,
null, UploadValuesAsyncWriteCallback, UploadValuesAsyncReadCallback, asyncOperation);
3270 ex2 =
new WebException(SR.GetString(
"net_webclient"), ex2);
3273 InvokeOperationCompleted(asyncOperation, uploadValuesOperationCompleted, eventArgs);
3277 Logging.Exit(Logging.Web,
this,
"UploadValuesAsync",
null);
3286 AbortRequest(webRequest);
3295 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3298 return DownloadStringTaskAsync(GetUri(address));
3307 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3319 DownloadStringCompleted += handler;
3322 DownloadStringAsync(address, tcs);
3326 DownloadStringCompleted -= handler;
3338 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3341 return OpenReadTaskAsync(GetUri(address));
3350 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3362 OpenReadCompleted += handler;
3365 OpenReadAsync(address, tcs);
3369 OpenReadCompleted -= handler;
3381 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3384 return OpenWriteTaskAsync(GetUri(address),
null);
3393 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3396 return OpenWriteTaskAsync(address,
null);
3406 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3409 return OpenWriteTaskAsync(GetUri(address), method);
3419 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3431 OpenWriteCompleted += handler;
3434 OpenWriteAsync(address, method, tcs);
3438 OpenWriteCompleted -= handler;
3453 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3456 return UploadStringTaskAsync(address,
null, data);
3468 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3471 return UploadStringTaskAsync(address,
null, data);
3485 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3488 return UploadStringTaskAsync(GetUri(address), method, data);
3502 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3514 UploadStringCompleted += handler;
3517 UploadStringAsync(address, method, data, tcs);
3521 UploadStringCompleted -= handler;
3533 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3536 return DownloadDataTaskAsync(GetUri(address));
3545 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3557 DownloadDataCompleted += handler;
3560 DownloadDataAsync(address, tcs);
3564 DownloadDataCompleted -= handler;
3578 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3581 return DownloadFileTaskAsync(GetUri(address), fileName);
3592 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3604 DownloadFileCompleted += handler;
3607 DownloadFileAsync(address, fileName, tcs);
3611 DownloadFileCompleted -= handler;
3624 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3627 return UploadDataTaskAsync(GetUri(address),
null, data);
3637 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3640 return UploadDataTaskAsync(address,
null, data);
3651 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3654 return UploadDataTaskAsync(GetUri(address), method, data);
3665 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3677 UploadDataCompleted += handler;
3680 UploadDataAsync(address, method, data, tcs);
3684 UploadDataCompleted -= handler;
3698 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3701 return UploadFileTaskAsync(GetUri(address),
null, fileName);
3712 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3715 return UploadFileTaskAsync(address,
null, fileName);
3727 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3730 return UploadFileTaskAsync(GetUri(address), method, fileName);
3742 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3754 UploadFileCompleted += handler;
3757 UploadFileAsync(address, method, fileName, tcs);
3761 UploadFileCompleted -= handler;
3774 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3777 return UploadValuesTaskAsync(GetUri(address),
null, data);
3789 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3792 return UploadValuesTaskAsync(GetUri(address), method, data);
3802 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3805 return UploadValuesTaskAsync(address,
null, data);
3817 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
3829 UploadValuesCompleted += handler;
3832 UploadValuesAsync(address, method, data, tcs);
3836 UploadValuesCompleted -= handler;
3842 private void HandleCompletion<TAsyncCompletedEventArgs, TCompletionDelegate, T>(
TaskCompletionSource<T> tcs, TAsyncCompletedEventArgs e, Func<TAsyncCompletedEventArgs, T> getResult, TCompletionDelegate handler, Action<WebClient, TCompletionDelegate> unregisterHandler) where TAsyncCompletedEventArgs :
AsyncCompletedEventArgs 3844 if (e.UserState == tcs)
3848 unregisterHandler(
this, handler);
3852 if (e.Error !=
null)
3854 tcs.TrySetException(e.Error);
3856 else if (e.Cancelled)
3858 tcs.TrySetCanceled();
3862 tcs.TrySetResult(getResult(e));
3872 if (this.DownloadProgressChanged !=
null)
3874 this.DownloadProgressChanged(
this, e);
3882 if (this.UploadProgressChanged !=
null)
3884 this.UploadProgressChanged(
this, e);
3888 private void ReportDownloadProgressChanged(
object arg)
3893 private void ReportUploadProgressChanged(
object arg)
3895 OnUploadProgressChanged((UploadProgressChangedEventArgs)arg);
3898 private void PostProgressChanged(
AsyncOperation asyncOp, ProgressData progress)
3900 if (asyncOp !=
null && progress.BytesSent + progress.BytesReceived > 0)
3902 if (progress.HasUploadPhase)
3904 int progressPercentage = (int)((progress.TotalBytesToReceive >= 0 || progress.BytesReceived != 0L) ? ((progress.TotalBytesToSend < 0) ? 50 : ((progress.TotalBytesToReceive == 0L) ? 100 : (50 * progress.BytesReceived / progress.TotalBytesToReceive + 50))) : ((progress.TotalBytesToSend >= 0) ? ((progress.TotalBytesToSend == 0L) ? 50 : (50 * progress.BytesSent / progress.TotalBytesToSend)) : 0));
3905 asyncOp.
Post(reportUploadProgressChanged,
new UploadProgressChangedEventArgs(progressPercentage, asyncOp.
UserSuppliedState, progress.BytesSent, progress.TotalBytesToSend, progress.BytesReceived, progress.TotalBytesToReceive));
3909 int progressPercentage = (int)((progress.TotalBytesToReceive >= 0) ? ((progress.TotalBytesToReceive == 0
L) ? 100 : (100 * progress.BytesReceived / progress.TotalBytesToReceive)) : 0);
3910 asyncOp.
Post(reportDownloadProgressChanged,
new DownloadProgressChangedEventArgs(progressPercentage, asyncOp.
UserSuppliedState, progress.BytesReceived, progress.TotalBytesToReceive));
UriKind
Defines the kinds of T:System.Uris for the M:System.Uri.IsWellFormedUriString(System....
Represents a character encoding.To browse the .NET Framework source code for this type,...
Stream Result
Gets a readable stream that contains data downloaded by a Overload:System.Net.WebClient....
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Provides concurrency management for classes that support asynchronous method calls....
DownloadProgressChangedEventHandler DownloadProgressChanged
Occurs when an asynchronous download operation successfully transfers some or all of the data.
Task< byte[]> UploadFileTaskAsync(string address, string fileName)
Uploads the specified local file to a resource as an asynchronous operation using a task object.
Task< Stream > OpenWriteTaskAsync(string address, string method)
Opens a stream for writing data to the specified resource as an asynchronous operation using a task o...
The exception that is thrown when an error occurs while accessing the network through a pluggable pro...
string UploadString(Uri address, string data)
Uploads the specified string to the specified resource, using the POST method.
abstract void Write(byte[] buffer, int offset, int count)
When overridden in a derived class, writes a sequence of bytes to the current stream and advances the...
string Result
Gets the server reply to a string upload operation that is started by calling an Overload:System....
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
unsafe string GetString(byte *bytes, int byteCount)
When overridden in a derived class, decodes a specified number of bytes starting at a specified addre...
abstract int Read([In] [Out] byte[] buffer, int offset, int count)
When overridden in a derived class, reads a sequence of bytes from the current stream and advances th...
string UploadString(Uri address, string method, string data)
Uploads the specified string to the specified resource, using the specified method.
Represents a collection of associated T:System.String keys and T:System.String values that can be acc...
WebClient()
Initializes a new instance of the T:System.Net.WebClient class.
Stream Result
Gets a writable stream that is used to send data to a server.
Task DownloadFileTaskAsync(string address, string fileName)
Downloads the specified resource to a local file as an asynchronous operation using a task object.
delegate void SendOrPostCallback(object state)
Represents a method to be called when a message is to be dispatched to a synchronization context.
Stream OpenRead(string address)
Opens a readable stream for the data downloaded from a resource with the URI specified as a T:System....
Task< string > UploadStringTaskAsync(string address, string method, string data)
Uploads the specified string to the specified resource as an asynchronous operation using a task obje...
virtual byte [] GetBytes(char[] chars)
When overridden in a derived class, encodes all the characters in the specified character array into ...
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
void UploadStringAsync(Uri address, string method, string data, object userToken)
Uploads the specified string to the specified resource. This method does not block the calling thread...
The exception that is thrown when the execution stack overflows because it contains too many nested m...
virtual WebResponse GetWebResponse(WebRequest request)
Returns the T:System.Net.WebResponse for the specified T:System.Net.WebRequest.
Provides data for the E:System.Net.WebClient.UploadDataCompleted event.
Tracks the lifetime of an asynchronous operation.
delegate void DownloadDataCompletedEventHandler(object sender, DownloadDataCompletedEventArgs e)
Represents the method that will handle the E:System.Net.WebClient.DownloadDataCompleted event of a T:...
static void SuppressFinalize(object obj)
Requests that the common language runtime not call the finalizer for the specified object.
virtual void OnUploadValuesCompleted(UploadValuesCompletedEventArgs e)
Raises the E:System.Net.WebClient.UploadValuesCompleted event.
delegate void UploadDataCompletedEventHandler(object sender, UploadDataCompletedEventArgs e)
Represents the method that will handle the E:System.Net.WebClient.UploadDataCompleted event of a T:Sy...
abstract bool CanSeek
When overridden in a derived class, gets a value indicating whether the current stream supports seeki...
void OpenReadAsync(Uri address, object userToken)
Opens a readable stream containing the specified resource. This method does not block the calling thr...
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
static Encoding Default
Gets an encoding for the operating system's current ANSI code page.
string UploadString(string address, string method, string data)
Uploads the specified string to the specified resource, using the specified method.
virtual int WriteTimeout
Gets or sets a value, in miliseconds, that determines how long the stream will attempt to write befor...
void UploadValuesAsync(Uri address, NameValueCollection data)
Uploads the data in the specified name/value collection to the resource identified by the specified U...
virtual string [] AllKeys
Gets all the keys in the T:System.Collections.Specialized.NameValueCollection.
FileMode
Specifies how the operating system should open a file.
Stream OpenWrite(Uri address)
Opens a stream for writing data to the specified resource.
EditorBrowsableState
Specifies the browsable state of a property or method from within an editor.
virtual RequestCachePolicy CachePolicy
Gets or sets the cache policy for this request.
static Encoding Unicode
Gets an encoding for the UTF-16 format using the little endian byte order.
The content of the collection was cleared.
Task< byte[]> UploadValuesTaskAsync(Uri address, string method, NameValueCollection data)
Uploads the specified name/value collection to the resource identified by the specified URI as an asy...
Makes a request to a Uniform Resource Identifier (URI). This is an abstract class.
delegate void DownloadProgressChangedEventHandler(object sender, DownloadProgressChangedEventArgs e)
Represents the method that will handle the E:System.Net.WebClient.DownloadProgressChanged event of a ...
static sbyte Min(sbyte val1, sbyte val2)
Returns the smaller of two 8-bit signed integers.
delegate void UploadStringCompletedEventHandler(object sender, UploadStringCompletedEventArgs e)
Represents the method that will handle the E:System.Net.WebClient.UploadStringCompleted event of a T:...
Task< string > UploadStringTaskAsync(Uri address, string method, string data)
Uploads the specified string to the specified resource as an asynchronous operation using a task obje...
Stream OpenWrite(string address)
Opens a stream for writing data to the specified resource.
Task< Stream > OpenWriteTaskAsync(Uri address)
Opens a stream for writing data to the specified resource as an asynchronous operation using a task o...
DownloadStringCompletedEventHandler DownloadStringCompleted
Occurs when an asynchronous resource-download operation completes.
string Scheme
Gets the scheme name for this URI.
abstract bool CanWrite
When overridden in a derived class, gets a value indicating whether the current stream supports writi...
Task< Stream > OpenWriteTaskAsync(Uri address, string method)
Opens a stream for writing data to the specified resource as an asynchronous operation using a task o...
Task< Stream > OpenReadTaskAsync(Uri address)
Opens a readable stream containing the specified resource as an asynchronous operation using a task o...
Provides common methods for sending data to and receiving data from a resource identified by a URI.
delegate void AsyncCallback(IAsyncResult ar)
References a method to be called when a corresponding asynchronous operation completes.
void UploadDataAsync(Uri address, string method, byte[] data)
Uploads a data buffer to a resource identified by a URI, using the specified method....
Task< Stream > OpenWriteTaskAsync(string address)
Opens a stream for writing data to the specified resource as an asynchronous operation using a task o...
void UploadDataAsync(Uri address, byte[] data)
Uploads a data buffer to a resource identified by a URI, using the POST method. This method does not ...
virtual WebRequest GetWebRequest(Uri address)
Returns a T:System.Net.WebRequest object for the specified resource.
Task< byte[]> UploadFileTaskAsync(Uri address, string fileName)
Uploads the specified local file to a resource as an asynchronous operation using a task object.
virtual void OnOpenWriteCompleted(OpenWriteCompletedEventArgs e)
Raises the E:System.Net.WebClient.OpenWriteCompleted event.
Task< string > DownloadStringTaskAsync(string address)
Downloads the resource as a T:System.String from the URI specified as an asynchronous operation using...
static string GetFileName(string path)
Returns the file name and extension of the specified path string.
byte [] Result
Gets the server reply to a data upload operation started by calling an Overload:System....
NameValueCollection QueryString
Gets or sets a collection of query name/value pairs associated with the request.
virtual void Close()
When overridden by a descendant class, closes the response stream.
Provides data for the E:System.Net.WebClient.OpenReadCompleted event.
virtual void OnDownloadProgressChanged(DownloadProgressChangedEventArgs e)
Raises the E:System.Net.WebClient.DownloadProgressChanged event.
void OpenWriteAsync(Uri address)
Opens a stream for writing data to the specified resource. This method does not block the calling thr...
static Encoding GetEncoding(int codepage)
Returns the encoding associated with the specified code page identifier.
string BaseAddress
Gets or sets the base URI for requests made by a T:System.Net.WebClient.
byte [] DownloadData(string address)
Downloads the resource as a T:System.Byte array from the URI specified.
WriteStreamClosedEventHandler WriteStreamClosed
Occurs when an asynchronous operation to write data to a resource using a write stream is closed.
byte [] UploadFile(string address, string method, string fileName)
Uploads the specified local file to the specified resource, using the specified method.
A type representing a date and time value.
void UploadValuesAsync(Uri address, string method, NameValueCollection data, object userToken)
Uploads the data in the specified name/value collection to the resource identified by the specified U...
byte [] UploadFile(string address, string fileName)
Uploads the specified local file to a resource with the specified URI.
RequestCachePolicy CachePolicy
Gets or sets the application's cache policy for any resources obtained by this WebClient instance usi...
abstract void SetLength(long value)
When overridden in a derived class, sets the length of the current stream.
SeekOrigin
Specifies the position in a stream to use for seeking.
void DownloadFileAsync(Uri address, string fileName, object userToken)
Downloads, to a local file, the resource with the specified URI. This method does not block the calli...
static Encoding ASCII
Gets an encoding for the ASCII (7-bit) character set.
virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Begins an asynchronous read operation. (Consider using M:System.IO.Stream.ReadAsync(System....
void UploadFileAsync(Uri address, string fileName)
Uploads the specified local file to the specified resource, using the POST method....
static Encoding BigEndianUnicode
Gets an encoding for the UTF-16 format that uses the big endian byte order.
WebHeaderCollection Headers
Gets or sets a collection of header name/value pairs associated with the request.
AsyncCompletedEventHandler DownloadFileCompleted
Occurs when an asynchronous file download operation completes.
Stream OpenWrite(Uri address, string method)
Opens a stream for writing data to the specified resource, by using the specified method.
bool AllowWriteStreamBuffering
Gets or sets a value that indicates whether to buffer the data written to the Internet resource for a...
virtual void OnOpenReadCompleted(OpenReadCompletedEventArgs e)
Raises the E:System.Net.WebClient.OpenReadCompleted event.
Provides data for the MethodNameCompleted event.
void OpenWriteAsync(Uri address, string method)
Opens a stream for writing data to the specified resource. This method does not block the calling thr...
abstract bool CanRead
When overridden in a derived class, gets a value indicating whether the current stream supports readi...
delegate void OpenWriteCompletedEventHandler(object sender, OpenWriteCompletedEventArgs e)
Represents the method that will handle the E:System.Net.WebClient.OpenWriteCompleted event of a T:Sys...
static Encoding UTF32
Gets an encoding for the UTF-32 format using the little endian byte order.
SecurityAction
Specifies the security actions that can be performed using declarative security.
virtual void OnDownloadDataCompleted(DownloadDataCompletedEventArgs e)
Raises the E:System.Net.WebClient.DownloadDataCompleted event.
void UploadStringAsync(Uri address, string method, string data)
Uploads the specified string to the specified resource. This method does not block the calling thread...
virtual void Close()
Closes the current stream and releases any resources (such as sockets and file handles) associated wi...
Provides a response from a Uniform Resource Identifier (URI). This is an abstract class.
Represents the status of an asynchronous operation.
UploadProgressChangedEventHandler UploadProgressChanged
Occurs when an asynchronous upload operation successfully transfers some or all of the data.
void DownloadFile(Uri address, string fileName)
Downloads the resource with the specified URI to a local file.
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
void DownloadDataAsync(Uri address)
Downloads the resource as a T:System.Byte array from the URI specified as an asynchronous operation.
static readonly Stream Null
A Stream with no backing store.
virtual Stream GetRequestStream()
When overridden in a descendant class, returns a T:System.IO.Stream for writing data to the Internet ...
void Dispose()
Releases all resources used by the T:System.ComponentModel.Component.
byte [] UploadFile(Uri address, string method, string fileName)
Uploads the specified local file to the specified resource, using the specified method.
void DownloadStringAsync(Uri address)
Downloads the resource specified as a T:System.Uri. This method does not block the calling thread.
virtual string Method
When overridden in a descendant class, gets or sets the protocol method to use in this request.
delegate void UploadProgressChangedEventHandler(object sender, UploadProgressChangedEventArgs e)
Represents the method that will handle the E:System.Net.WebClient.UploadProgressChanged event of a T:...
byte [] UploadValues(string address, NameValueCollection data)
Uploads the specified name/value collection to the resource identified by the specified URI.
Provides data for the E:System.Net.WebClient.UploadStringCompleted event.
virtual int ReadTimeout
Gets or sets a value, in miliseconds, that determines how long the stream will attempt to read before...
Task< byte[]> UploadValuesTaskAsync(string address, string method, NameValueCollection data)
Uploads the specified name/value collection to the resource identified by the specified URI as an asy...
void DownloadDataAsync(Uri address, object userToken)
Downloads the resource as a T:System.Byte array from the URI specified as an asynchronous operation.
byte [] UploadData(Uri address, string method, byte[] data)
Uploads a data buffer to the specified resource, using the specified method.
UploadValuesCompletedEventHandler UploadValuesCompleted
Occurs when an asynchronous upload of a name/value collection completes.
Task< byte[]> UploadValuesTaskAsync(Uri address, NameValueCollection data)
Uploads the specified name/value collection to the resource identified by the specified URI as an asy...
Provides storage for multiple credentials.
delegate void WriteStreamClosedEventHandler(object sender, WriteStreamClosedEventArgs e)
Represents the method that will handle the E:System.Net.WebClient.WriteStreamClosed event of a T:Syst...
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
Provides data for the E:System.Net.WebClient.OpenWriteCompleted event.
Task DownloadFileTaskAsync(Uri address, string fileName)
Downloads the specified resource to a local file as an asynchronous operation using a task object.
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
byte [] UploadFile(Uri address, string fileName)
Uploads the specified local file to a resource with the specified URI.
byte [] UploadData(string address, byte[] data)
Uploads a data buffer to a resource identified by a URI.
void UploadFileAsync(Uri address, string method, string fileName, object userToken)
Uploads the specified local file to the specified resource, using the POST method....
Task< byte[]> UploadValuesTaskAsync(string address, NameValueCollection data)
Uploads the specified name/value collection to the resource identified by the specified URI as an asy...
Task< byte[]> UploadDataTaskAsync(Uri address, byte[] data)
Uploads a data buffer that contains a T:System.Byte array to the URI specified as an asynchronous ope...
void UploadStringAsync(Uri address, string data)
Uploads the specified string to the specified resource. This method does not block the calling thread...
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Copies a specified number of bytes from a source array starting at a particular offset to a destinati...
Task< string > UploadStringTaskAsync(Uri address, string data)
Uploads the specified string to the specified resource as an asynchronous operation using a task obje...
static int Increment(ref int location)
Increments a specified variable and stores the result, as an atomic operation.
abstract void Flush()
When overridden in a derived class, clears all buffers for this stream and causes any buffered data t...
void DownloadFileAsync(Uri address, string fileName)
Downloads, to a local file, the resource with the specified URI. This method does not block the calli...
static ICredentials DefaultCredentials
Gets the system credentials of the application.
void UploadFileAsync(Uri address, string method, string fileName)
Uploads the specified local file to the specified resource, using the POST method....
UploadStringCompletedEventHandler UploadStringCompleted
Occurs when an asynchronous string-upload operation completes.
byte [] Result
Gets the server reply to a data upload operation started by calling an Overload:System....
Represents the producer side of a T:System.Threading.Tasks.Task`1 unbound to a delegate,...
Provides the base authentication interface for retrieving credentials for Web client authentication.
virtual void OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
Raises the E:System.Net.WebClient.DownloadStringCompleted event.
Provides the base implementation for the T:System.ComponentModel.IComponent interface and enables obj...
UploadFileCompletedEventHandler UploadFileCompleted
Occurs when an asynchronous file-upload operation completes.
virtual WebResponse GetWebResponse(WebRequest request, IAsyncResult result)
Returns the T:System.Net.WebResponse for the specified T:System.Net.WebRequest using the specified T:...
The exception that is thrown when there is not enough memory to continue the execution of a program.
string Result
Gets the data that is downloaded by a Overload:System.Net.WebClient.DownloadStringAsync method.
static string GetFullPath(string path)
Returns the absolute path for the specified path string.
void DownloadFile(string address, string fileName)
Downloads the resource with the specified URI to a local file.
bool? UseDefaultCredentials
Gets or sets a T:System.Boolean value that controls whether the P:System.Net.CredentialCache....
virtual long ContentLength
When overridden in a descendant class, gets or sets the content length of the request data being sent...
UploadDataCompletedEventHandler UploadDataCompleted
Occurs when an asynchronous data-upload operation completes.
abstract long Seek(long offset, SeekOrigin origin)
When overridden in a derived class, sets the position within the current stream.
virtual bool CanTimeout
Gets a value that determines whether the current stream can time out.
Task< Stream > OpenReadTaskAsync(string address)
Opens a readable stream containing the specified resource as an asynchronous operation using a task o...
delegate void DownloadStringCompletedEventHandler(object sender, DownloadStringCompletedEventArgs e)
Represents the method that will handle the E:System.Net.WebClient.DownloadStringCompleted event of a ...
virtual void OnUploadStringCompleted(UploadStringCompletedEventArgs e)
Raises the E:System.Net.WebClient.UploadStringCompleted event.
Task< TResult > Task
Gets the T:System.Threading.Tasks.Task`1 created by this T:System.Threading.Tasks....
Defines an application's caching requirements for resources obtained by using T:System....
Stream OpenRead(Uri address)
Opens a readable stream for the data downloaded from a resource with the URI specified as a T:System....
byte [] UploadValues(Uri address, NameValueCollection data)
Uploads the specified name/value collection to the resource identified by the specified URI.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
virtual ICredentials Credentials
When overridden in a descendant class, gets or sets the network credentials used for authenticating t...
static readonly string UriSchemeFile
Specifies that the URI is a pointer to a file. This field is read-only.
Controls the system garbage collector, a service that automatically reclaims unused memory.
virtual void OnUploadProgressChanged(UploadProgressChangedEventArgs e)
Raises the E:System.Net.WebClient.UploadProgressChanged event.
string UploadString(string address, string data)
Uploads the specified string to the specified resource, using the POST method.
virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Begins an asynchronous write operation. (Consider using M:System.IO.Stream.WriteAsync(System....
ICredentials Credentials
Gets or sets the network credentials that are sent to the host and used to authenticate the request.
virtual void OnWriteStreamClosed(WriteStreamClosedEventArgs e)
Raises the E:System.Net.WebClient.WriteStreamClosed event.
WebExceptionStatus
Defines status codes for the T:System.Net.WebException class.
OpenWriteCompletedEventHandler OpenWriteCompleted
Occurs when an asynchronous operation to open a stream to write data to a resource completes.
bool IsBusy
Gets whether a Web request is in progress.
The exception that is thrown when one of the arguments provided to a method is not valid.
abstract long Length
When overridden in a derived class, gets the length in bytes of the stream.
virtual void Abort()
Aborts the Request
Task< byte[]> UploadFileTaskAsync(Uri address, string method, string fileName)
Uploads the specified local file to a resource as an asynchronous operation using a task object.
virtual void OnDownloadFileCompleted(AsyncCompletedEventArgs e)
Raises the E:System.Net.WebClient.DownloadFileCompleted event.
byte [] UploadValues(Uri address, string method, NameValueCollection data)
Uploads the specified name/value collection to the resource identified by the specified URI,...
virtual long ContentLength
When overridden in a descendant class, gets or sets the content length of data being received.
virtual void OnUploadDataCompleted(UploadDataCompletedEventArgs e)
Raises the E:System.Net.WebClient.UploadDataCompleted event.
WebHeaderCollection ResponseHeaders
Gets a collection of header name/value pairs associated with the response.
void UploadValuesAsync(Uri address, string method, NameValueCollection data)
Uploads the data in the specified name/value collection to the resource identified by the specified U...
string DownloadString(Uri address)
Downloads the requested resource as a T:System.String. The resource to download is specified as a T:S...
virtual byte [] GetPreamble()
When overridden in a derived class, returns a sequence of bytes that specifies the encoding used.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
FileAccess
Defines constants for read, write, or read/write access to a file.
void Post(SendOrPostCallback d, object arg)
Invokes a delegate on the thread or context appropriate for the application model.
static AsyncOperation CreateOperation(object userSuppliedState)
Returns an T:System.ComponentModel.AsyncOperation for tracking the duration of a particular asynchron...
Creates or manipulates threads other than its own, which might be harmful to the host.
object UserSuppliedState
Gets or sets an object used to uniquely identify an asynchronous operation.
OpenReadCompletedEventHandler OpenReadCompleted
Occurs when an asynchronous operation to open a stream containing a resource completes.
byte [] UploadData(string address, string method, byte[] data)
Uploads a data buffer to the specified resource, using the specified method.
delegate void OpenReadCompletedEventHandler(object sender, OpenReadCompletedEventArgs e)
Represents the method that will handle the E:System.Net.WebClient.OpenReadCompleted event of a T:Syst...
delegate void UploadFileCompletedEventHandler(object sender, UploadFileCompletedEventArgs e)
Represents the method that will handle the E:System.Net.WebClient.UploadFileCompleted event of a T:Sy...
Provides data for the E:System.Net.WebClient.DownloadDataCompleted event.
byte [] Result
Gets the data that is downloaded by a Overload:System.Net.WebClient.DownloadDataAsync method.
void PostOperationCompleted(SendOrPostCallback d, object arg)
Ends the lifetime of an asynchronous operation.
abstract long Position
When overridden in a derived class, gets or sets the position within the current stream.
virtual IWebProxy Proxy
When overridden in a descendant class, gets or sets the network proxy to use to access this Internet ...
Provides data for the E:System.Net.WebClient.UploadFileCompleted event.
virtual int Count
Gets the number of key/value pairs contained in the T:System.Collections.Specialized....
virtual void OnUploadFileCompleted(UploadFileCompletedEventArgs e)
Raises the E:System.Net.WebClient.UploadFileCompleted event.
string DownloadString(string address)
Downloads the requested resource as a T:System.String. The resource to download is specified as a T:S...
static Encoding UTF8
Gets an encoding for the UTF-8 format.
void OpenWriteAsync(Uri address, string method, object userToken)
Opens a stream for writing data to the specified resource, using the specified method....
Stream OpenWrite(string address, string method)
Opens a stream for writing data to the specified resource, using the specified method.
void OpenReadAsync(Uri address)
Opens a readable stream containing the specified resource. This method does not block the calling thr...
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
Manipulates arrays of primitive types.
bool AllowReadStreamBuffering
Gets or sets a value that indicates whether to buffer the data read from the Internet resource for a ...
byte [] UploadValues(string address, string method, NameValueCollection data)
Uploads the specified name/value collection to the resource identified by the specified URI,...
Task< byte[]> UploadDataTaskAsync(Uri address, string method, byte[] data)
Uploads a data buffer that contains a T:System.Byte array to the URI specified as an asynchronous ope...
static void Delete(string path)
Deletes the specified file.
Provides data for the E:System.Net.WebClient.WriteStreamClosed event.
Provides the base interface for implementation of proxy access for the T:System.Net....
void DownloadStringAsync(Uri address, object userToken)
Downloads the specified string to the specified resource. This method does not block the calling thre...
Provides data for the E:System.Net.WebClient.DownloadProgressChanged event of a T:System....
virtual int EndRead(IAsyncResult asyncResult)
Waits for the pending asynchronous read to complete. (Consider using M:System.IO.Stream....
virtual WebResponse GetResponse()
When overridden in a descendant class, returns a response to an Internet request.
Task< byte[]> UploadDataTaskAsync(string address, byte[] data)
Uploads a data buffer that contains a T:System.Byte array to the URI specified as an asynchronous ope...
static int Decrement(ref int location)
Decrements a specified variable and stores the result, as an atomic operation.
Provides constants and static methods for trigonometric, logarithmic, and other common mathematical f...
Provides information about a specific culture (called a locale for unmanaged code development)....
byte [] DownloadData(Uri address)
Downloads the resource as a T:System.Byte array from the URI specified.
void CancelAsync()
Cancels a pending asynchronous operation.
delegate void UploadValuesCompletedEventHandler(object sender, UploadValuesCompletedEventArgs e)
Represents the method that will handle the E:System.Net.WebClient.UploadValuesCompleted event of a T:...
Task< byte[]> DownloadDataTaskAsync(string address)
Downloads the resource as a T:System.Byte array from the URI specified as an asynchronous operation u...
The exception that is thrown when a call is made to the M:System.Threading.Thread....
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
IWebProxy Proxy
Gets or sets the proxy used by this T:System.Net.WebClient object.
virtual Stream GetResponseStream()
When overridden in a descendant class, returns the data stream from the Internet resource.
Provides data for the E:System.Net.WebClient.DownloadStringCompleted event.
delegate void AsyncCompletedEventHandler(object sender, AsyncCompletedEventArgs e)
Represents the method that will handle the MethodNameCompleted event of an asynchronous operation.
byte [] UploadData(Uri address, byte[] data)
Uploads a data buffer to a resource identified by a URI.
Provides data for the E:System.Net.WebClient.UploadProgressChanged event of a T:System....
Task< byte[]> DownloadDataTaskAsync(Uri address)
Downloads the resource as a T:System.Byte array from the URI specified as an asynchronous operation u...
Provides an T:System.IProgress`1 that invokes callbacks for each reported progress value.
virtual WebResponse EndGetResponse(IAsyncResult asyncResult)
When overridden in a descendant class, returns a T:System.Net.WebResponse.
Provides atomic operations for variables that are shared by multiple threads.
override string ToString()
Gets a canonical string representation for the specified T:System.Uri instance.
The exception that is thrown when a security error is detected.
DownloadDataCompletedEventHandler DownloadDataCompleted
Occurs when an asynchronous data download operation completes.
Performs operations on T:System.String instances that contain file or directory path information....
byte [] Result
Gets the server reply to a data upload operation that is started by calling an Overload:System....
virtual void EndWrite(IAsyncResult asyncResult)
Ends an asynchronous write operation. (Consider using M:System.IO.Stream.WriteAsync(System....
Provides data for the E:System.Net.WebClient.UploadValuesCompleted event.
Task< string > UploadStringTaskAsync(string address, string data)
Uploads the specified string to the specified resource as an asynchronous operation using a task obje...
void UploadDataAsync(Uri address, string method, byte[] data, object userToken)
Uploads a data buffer to a resource identified by a URI, using the specified method and identifying t...
virtual WebHeaderCollection Headers
When overridden in a derived class, gets a collection of header name-value pairs associated with this...
Represents an asynchronous operation that can return a value.
Task< byte[]> UploadFileTaskAsync(string address, string method, string fileName)
Uploads the specified local file to a resource as an asynchronous operation using a task object.
Task< byte[]> UploadDataTaskAsync(string address, string method, byte[] data)
Uploads a data buffer that contains a T:System.Byte array to the URI specified as an asynchronous ope...
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....
Task< string > DownloadStringTaskAsync(Uri address)
Downloads the resource as a T:System.String from the URI specified as an asynchronous operation using...