Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WebClient.cs
Go to the documentation of this file.
4using System.IO;
7using System.Text;
10
11namespace System.Net;
12
13public class WebClient : Component
14{
15 private sealed class ProgressData
16 {
17 internal long BytesSent;
18
19 internal long TotalBytesToSend = -1L;
20
21 internal long BytesReceived;
22
23 internal long TotalBytesToReceive = -1L;
24
25 internal bool HasUploadPhase;
26
27 internal void Reset()
28 {
29 BytesSent = 0L;
33 HasUploadPhase = false;
34 }
35 }
36
38 {
39 private readonly WebRequest _request;
40
41 private readonly WebClient _webClient;
42
44 : base(stream)
45 {
46 _request = request;
47 _webClient = webClient;
48 }
49
50 protected override void Dispose(bool disposing)
51 {
52 try
53 {
54 if (disposing)
55 {
57 }
58 }
59 finally
60 {
61 base.Dispose(disposing);
62 }
63 }
64 }
65
67
69
71
73
75
77
79
80 private string _method;
81
82 private long _contentLength = -1L;
83
84 private bool _initWebClientAsync;
85
86 private bool _canceled;
87
89
91
92 private bool _proxySet;
93
94 private int _callNesting;
95
97
98 private SendOrPostCallback _downloadDataOperationCompleted;
99
100 private SendOrPostCallback _openReadOperationCompleted;
101
102 private SendOrPostCallback _openWriteOperationCompleted;
103
104 private SendOrPostCallback _downloadStringOperationCompleted;
105
106 private SendOrPostCallback _downloadFileOperationCompleted;
107
108 private SendOrPostCallback _uploadStringOperationCompleted;
109
110 private SendOrPostCallback _uploadDataOperationCompleted;
111
112 private SendOrPostCallback _uploadFileOperationCompleted;
113
114 private SendOrPostCallback _uploadValuesOperationCompleted;
115
116 private SendOrPostCallback _reportDownloadProgressChanged;
117
118 private SendOrPostCallback _reportUploadProgressChanged;
119
120 private static readonly char[] s_parseContentTypeSeparators = new char[3] { ';', '=', ' ' };
121
122 private static readonly Encoding[] s_knownEncodings = new Encoding[4]
123 {
127 System.Text.Encoding.BigEndianUnicode
128 };
129
131 {
132 get
133 {
134 return _encoding;
135 }
136 set
137 {
140 }
141 }
142
143 public string BaseAddress
144 {
145 get
146 {
147 if (!(_baseAddress != null))
148 {
149 return string.Empty;
150 }
151 return _baseAddress.ToString();
152 }
153 [param: AllowNull]
154 set
155 {
156 if (string.IsNullOrEmpty(value))
157 {
158 _baseAddress = null;
159 return;
160 }
161 try
162 {
163 _baseAddress = new Uri(value);
164 }
165 catch (UriFormatException innerException)
166 {
167 throw new ArgumentException(System.SR.net_webclient_invalid_baseaddress, "value", innerException);
168 }
169 }
170 }
171
173 {
174 get
175 {
176 return _credentials;
177 }
178 set
179 {
181 }
182 }
183
185 {
186 get
187 {
189 }
190 set
191 {
192 _credentials = (value ? CredentialCache.DefaultCredentials : null);
193 }
194 }
195
196 public WebHeaderCollection Headers
197 {
198 get
199 {
200 return _headers ?? (_headers = new WebHeaderCollection());
201 }
202 [param: AllowNull]
203 set
204 {
205 _headers = value;
206 }
207 }
208
210 {
211 get
212 {
214 }
215 [param: AllowNull]
216 set
217 {
219 }
220 }
221
223
225 {
226 get
227 {
228 if (!_proxySet)
229 {
231 }
232 return _proxy;
233 }
234 set
235 {
236 _proxy = value;
237 _proxySet = true;
238 }
239 }
240
241 public RequestCachePolicy? CachePolicy { get; set; }
242
243 public bool IsBusy => Volatile.Read(ref _callNesting) > 0;
244
245 [Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
246 [EditorBrowsable(EditorBrowsableState.Never)]
247 public bool AllowReadStreamBuffering { get; set; }
248
249 [Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
250 [EditorBrowsable(EditorBrowsableState.Never)]
251 public bool AllowWriteStreamBuffering { get; set; }
252
254
256
258
260
262
264
266
268
270
272
274
275 [Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
276 [EditorBrowsable(EditorBrowsableState.Never)]
278 {
279 add
280 {
281 }
282 remove
283 {
284 }
285 }
286
287 [Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
288 public WebClient()
289 {
290 if (GetType() == typeof(WebClient))
291 {
292 GC.SuppressFinalize(this);
293 }
294 }
295
297 {
298 this.DownloadStringCompleted?.Invoke(this, e);
299 }
300
302 {
303 this.DownloadDataCompleted?.Invoke(this, e);
304 }
305
307 {
308 this.DownloadFileCompleted?.Invoke(this, e);
309 }
310
312 {
313 this.DownloadProgressChanged?.Invoke(this, e);
314 }
315
317 {
318 this.UploadStringCompleted?.Invoke(this, e);
319 }
320
322 {
323 this.UploadDataCompleted?.Invoke(this, e);
324 }
325
327 {
328 this.UploadFileCompleted?.Invoke(this, e);
329 }
330
332 {
333 this.UploadValuesCompleted?.Invoke(this, e);
334 }
335
337 {
338 this.UploadProgressChanged?.Invoke(this, e);
339 }
340
342 {
343 this.OpenReadCompleted?.Invoke(this, e);
344 }
345
347 {
348 this.OpenWriteCompleted?.Invoke(this, e);
349 }
350
351 private void StartOperation()
352 {
354 {
355 EndOperation();
357 }
358 _contentLength = -1L;
359 _webResponse = null;
360 _webRequest = null;
361 _method = null;
362 _canceled = false;
363 _progress?.Reset();
364 }
365
366 private AsyncOperation StartAsyncOperation(object userToken)
367 {
369 {
370 _openReadOperationCompleted = delegate(object arg)
371 {
373 };
374 _openWriteOperationCompleted = delegate(object arg)
375 {
377 };
378 _downloadStringOperationCompleted = delegate(object arg)
379 {
381 };
382 _downloadDataOperationCompleted = delegate(object arg)
383 {
385 };
386 _downloadFileOperationCompleted = delegate(object arg)
387 {
389 };
390 _uploadStringOperationCompleted = delegate(object arg)
391 {
393 };
394 _uploadDataOperationCompleted = delegate(object arg)
395 {
397 };
398 _uploadFileOperationCompleted = delegate(object arg)
399 {
401 };
402 _uploadValuesOperationCompleted = delegate(object arg)
403 {
405 };
406 _reportDownloadProgressChanged = delegate(object arg)
407 {
409 };
410 _reportUploadProgressChanged = delegate(object arg)
411 {
413 };
414 _progress = new ProgressData();
415 _initWebClientAsync = true;
416 }
417 AsyncOperation asyncOperation = AsyncOperationManager.CreateOperation(userToken);
419 _asyncOp = asyncOperation;
420 return asyncOperation;
421 }
422
423 private void EndOperation()
424 {
426 }
427
428 protected virtual WebRequest GetWebRequest(Uri address)
429 {
430 WebRequest webRequest = WebRequest.Create(address);
431 CopyHeadersTo(webRequest);
432 if (Credentials != null)
433 {
434 webRequest.Credentials = Credentials;
435 }
436 if (_method != null)
437 {
438 webRequest.Method = _method;
439 }
440 if (_contentLength != -1)
441 {
442 webRequest.ContentLength = _contentLength;
443 }
444 if (_proxySet)
445 {
446 webRequest.Proxy = _proxy;
447 }
448 if (CachePolicy != null)
449 {
450 webRequest.CachePolicy = CachePolicy;
451 }
452 return webRequest;
453 }
454
455 protected virtual WebResponse GetWebResponse(WebRequest request)
456 {
457 return _webResponse = request.GetResponse();
458 }
459
460 protected virtual WebResponse GetWebResponse(WebRequest request, IAsyncResult result)
461 {
462 return _webResponse = request.EndGetResponse(result);
463 }
464
466 {
467 BeginEndAwaitableAdapter beginEndAwaitableAdapter = new BeginEndAwaitableAdapter();
468 request.BeginGetResponse(BeginEndAwaitableAdapter.Callback, beginEndAwaitableAdapter);
469 return GetWebResponse(request, await beginEndAwaitableAdapter);
470 }
471
472 public byte[] DownloadData(string address)
473 {
474 return DownloadData(GetUri(address));
475 }
476
477 public byte[] DownloadData(Uri address)
478 {
479 ArgumentNullException.ThrowIfNull(address, "address");
481 try
482 {
483 WebRequest request;
484 return DownloadDataInternal(address, out request);
485 }
486 finally
487 {
488 EndOperation();
489 }
490 }
491
492 private byte[] DownloadDataInternal(Uri address, out WebRequest request)
493 {
494 WebRequest webRequest = null;
495 byte[] result;
496 try
497 {
498 webRequest = (_webRequest = GetWebRequest(GetUri(address)));
499 result = DownloadBits(webRequest, new ChunkedMemoryStream());
500 }
501 catch (Exception ex) when (!(ex is OutOfMemoryException))
502 {
503 AbortRequest(webRequest);
504 if (ex is WebException || ex is SecurityException)
505 {
506 throw;
507 }
508 throw new WebException(System.SR.net_webclient, ex);
509 }
510 request = webRequest;
511 return result;
512 }
513
514 public void DownloadFile(string address, string fileName)
515 {
516 DownloadFile(GetUri(address), fileName);
517 }
518
519 public void DownloadFile(Uri address, string fileName)
520 {
521 ArgumentNullException.ThrowIfNull(address, "address");
522 ArgumentNullException.ThrowIfNull(fileName, "fileName");
523 WebRequest request = null;
524 FileStream fileStream = null;
525 bool flag = false;
527 try
528 {
529 fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
530 request = (_webRequest = GetWebRequest(GetUri(address)));
531 DownloadBits(request, fileStream);
532 flag = true;
533 }
534 catch (Exception ex) when (!(ex is OutOfMemoryException))
535 {
536 AbortRequest(request);
537 if (ex is WebException || ex is SecurityException)
538 {
539 throw;
540 }
541 throw new WebException(System.SR.net_webclient, ex);
542 }
543 finally
544 {
545 if (fileStream != null)
546 {
547 fileStream.Close();
548 if (!flag)
549 {
550 File.Delete(fileName);
551 }
552 }
553 EndOperation();
554 }
555 }
556
557 public Stream OpenRead(string address)
558 {
559 return OpenRead(GetUri(address));
560 }
561
562 public Stream OpenRead(Uri address)
563 {
564 ArgumentNullException.ThrowIfNull(address, "address");
565 WebRequest request = null;
567 try
568 {
569 request = (_webRequest = GetWebRequest(GetUri(address)));
570 return (_webResponse = GetWebResponse(request)).GetResponseStream();
571 }
572 catch (Exception ex) when (!(ex is OutOfMemoryException))
573 {
574 AbortRequest(request);
575 if (ex is WebException || ex is SecurityException)
576 {
577 throw;
578 }
579 throw new WebException(System.SR.net_webclient, ex);
580 }
581 finally
582 {
583 EndOperation();
584 }
585 }
586
587 public Stream OpenWrite(string address)
588 {
589 return OpenWrite(GetUri(address), null);
590 }
591
592 public Stream OpenWrite(Uri address)
593 {
594 return OpenWrite(address, null);
595 }
596
597 public Stream OpenWrite(string address, string? method)
598 {
599 return OpenWrite(GetUri(address), method);
600 }
601
602 public Stream OpenWrite(Uri address, string? method)
603 {
604 ArgumentNullException.ThrowIfNull(address, "address");
605 if (method == null)
606 {
607 method = MapToDefaultMethod(address);
608 }
609 WebRequest webRequest = null;
611 try
612 {
613 _method = method;
614 webRequest = (_webRequest = GetWebRequest(GetUri(address)));
615 return new WebClientWriteStream(webRequest.GetRequestStream(), webRequest, this);
616 }
617 catch (Exception ex) when (!(ex is OutOfMemoryException))
618 {
619 AbortRequest(webRequest);
620 if (ex is WebException || ex is SecurityException)
621 {
622 throw;
623 }
624 throw new WebException(System.SR.net_webclient, ex);
625 }
626 finally
627 {
628 EndOperation();
629 }
630 }
631
632 public byte[] UploadData(string address, byte[] data)
633 {
634 return UploadData(GetUri(address), null, data);
635 }
636
637 public byte[] UploadData(Uri address, byte[] data)
638 {
639 return UploadData(address, null, data);
640 }
641
642 public byte[] UploadData(string address, string? method, byte[] data)
643 {
644 return UploadData(GetUri(address), method, data);
645 }
646
647 public byte[] UploadData(Uri address, string? method, byte[] data)
648 {
649 ArgumentNullException.ThrowIfNull(address, "address");
651 if (method == null)
652 {
653 method = MapToDefaultMethod(address);
654 }
656 try
657 {
658 WebRequest request;
659 return UploadDataInternal(address, method, data, out request);
660 }
661 finally
662 {
663 EndOperation();
664 }
665 }
666
667 private byte[] UploadDataInternal(Uri address, string method, byte[] data, out WebRequest request)
668 {
669 WebRequest webRequest = null;
670 byte[] result;
671 try
672 {
673 _method = method;
674 _contentLength = data.Length;
675 webRequest = (_webRequest = GetWebRequest(GetUri(address)));
676 result = UploadBits(webRequest, null, data, 0, null, null);
677 }
678 catch (Exception ex) when (!(ex is OutOfMemoryException))
679 {
680 AbortRequest(webRequest);
681 if (ex is WebException || ex is SecurityException)
682 {
683 throw;
684 }
685 throw new WebException(System.SR.net_webclient, ex);
686 }
687 request = webRequest;
688 return result;
689 }
690
691 private void OpenFileInternal(bool needsHeaderAndBoundary, string fileName, out FileStream fs, out byte[] buffer, ref byte[] formHeaderBytes, ref byte[] boundaryBytes)
692 {
693 fileName = Path.GetFullPath(fileName);
695 string text = headers["Content-Type"];
696 if (text == null)
697 {
698 text = "application/octet-stream";
699 }
700 else if (text.StartsWith("multipart/", StringComparison.OrdinalIgnoreCase))
701 {
703 }
704 fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
705 int num = 8192;
706 _contentLength = -1L;
707 if (string.Equals(_method, "POST", StringComparison.Ordinal))
708 {
709 if (needsHeaderAndBoundary)
710 {
711 string text2 = $"---------------------{DateTime.Now.Ticks:x}";
712 headers["Content-Type"] = "multipart/form-data; boundary=" + text2;
713 string s = "--" + text2 + "\r\nContent-Disposition: form-data; name=\"file\"; filename=\"" + Path.GetFileName(fileName) + "\"\r\nContent-Type: " + text + "\r\n\r\n";
714 formHeaderBytes = System.Text.Encoding.UTF8.GetBytes(s);
715 boundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + text2 + "--\r\n");
716 }
717 else
718 {
719 formHeaderBytes = Array.Empty<byte>();
720 boundaryBytes = Array.Empty<byte>();
721 }
722 if (fs.CanSeek)
723 {
724 _contentLength = fs.Length + formHeaderBytes.Length + boundaryBytes.Length;
725 num = (int)Math.Min(8192L, fs.Length);
726 }
727 }
728 else
729 {
730 headers["Content-Type"] = text;
731 formHeaderBytes = null;
732 boundaryBytes = null;
733 if (fs.CanSeek)
734 {
735 _contentLength = fs.Length;
736 num = (int)Math.Min(8192L, fs.Length);
737 }
738 }
739 buffer = new byte[num];
740 }
741
742 public byte[] UploadFile(string address, string fileName)
743 {
744 return UploadFile(GetUri(address), fileName);
745 }
746
747 public byte[] UploadFile(Uri address, string fileName)
748 {
749 return UploadFile(address, null, fileName);
750 }
751
752 public byte[] UploadFile(string address, string? method, string fileName)
753 {
754 return UploadFile(GetUri(address), method, fileName);
755 }
756
757 public byte[] UploadFile(Uri address, string? method, string fileName)
758 {
759 ArgumentNullException.ThrowIfNull(address, "address");
760 ArgumentNullException.ThrowIfNull(fileName, "fileName");
761 if (method == null)
762 {
763 method = MapToDefaultMethod(address);
764 }
765 FileStream fs = null;
766 WebRequest request = null;
768 try
769 {
770 _method = method;
771 byte[] formHeaderBytes = null;
772 byte[] boundaryBytes = null;
773 Uri uri = GetUri(address);
774 bool needsHeaderAndBoundary = uri.Scheme != Uri.UriSchemeFile;
775 OpenFileInternal(needsHeaderAndBoundary, fileName, out fs, out var buffer, ref formHeaderBytes, ref boundaryBytes);
776 request = (_webRequest = GetWebRequest(uri));
777 return UploadBits(request, fs, buffer, 0, formHeaderBytes, boundaryBytes);
778 }
779 catch (Exception ex)
780 {
781 fs?.Close();
782 if (ex is OutOfMemoryException)
783 {
784 throw;
785 }
786 AbortRequest(request);
787 if (ex is WebException || ex is SecurityException)
788 {
789 throw;
790 }
791 throw new WebException(System.SR.net_webclient, ex);
792 }
793 finally
794 {
795 EndOperation();
796 }
797 }
798
800 {
802 string text = headers["Content-Type"];
803 if (text != null && !string.Equals(text, "application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase))
804 {
806 }
807 headers["Content-Type"] = "application/x-www-form-urlencoded";
808 string value = string.Empty;
809 StringBuilder stringBuilder = new StringBuilder();
810 string[] allKeys = data.AllKeys;
811 foreach (string text2 in allKeys)
812 {
813 stringBuilder.Append(value);
814 stringBuilder.Append(UrlEncode(text2));
815 stringBuilder.Append('=');
816 stringBuilder.Append(UrlEncode(data[text2]));
817 value = "&";
818 }
819 byte[] bytes = System.Text.Encoding.ASCII.GetBytes(stringBuilder.ToString());
820 _contentLength = bytes.Length;
821 return bytes;
822 }
823
824 public byte[] UploadValues(string address, NameValueCollection data)
825 {
826 return UploadValues(GetUri(address), null, data);
827 }
828
829 public byte[] UploadValues(Uri address, NameValueCollection data)
830 {
831 return UploadValues(address, null, data);
832 }
833
834 public byte[] UploadValues(string address, string? method, NameValueCollection data)
835 {
836 return UploadValues(GetUri(address), method, data);
837 }
838
839 public byte[] UploadValues(Uri address, string? method, NameValueCollection data)
840 {
841 ArgumentNullException.ThrowIfNull(address, "address");
843 if (method == null)
844 {
845 method = MapToDefaultMethod(address);
846 }
847 WebRequest request = null;
849 try
850 {
851 byte[] valuesToUpload = GetValuesToUpload(data);
852 _method = method;
853 request = (_webRequest = GetWebRequest(GetUri(address)));
854 return UploadBits(request, null, valuesToUpload, 0, null, null);
855 }
856 catch (Exception ex) when (!(ex is OutOfMemoryException))
857 {
858 AbortRequest(request);
859 if (ex is WebException || ex is SecurityException)
860 {
861 throw;
862 }
863 throw new WebException(System.SR.net_webclient, ex);
864 }
865 finally
866 {
867 EndOperation();
868 }
869 }
870
871 public string UploadString(string address, string data)
872 {
873 return UploadString(GetUri(address), null, data);
874 }
875
876 public string UploadString(Uri address, string data)
877 {
878 return UploadString(address, null, data);
879 }
880
881 public string UploadString(string address, string? method, string data)
882 {
883 return UploadString(GetUri(address), method, data);
884 }
885
886 public string UploadString(Uri address, string? method, string data)
887 {
888 ArgumentNullException.ThrowIfNull(address, "address");
890 if (method == null)
891 {
892 method = MapToDefaultMethod(address);
893 }
895 try
896 {
897 byte[] bytes = Encoding.GetBytes(data);
898 WebRequest request;
899 byte[] data2 = UploadDataInternal(address, method, bytes, out request);
900 return GetStringUsingEncoding(request, data2);
901 }
902 finally
903 {
904 EndOperation();
905 }
906 }
907
908 public string DownloadString(string address)
909 {
910 return DownloadString(GetUri(address));
911 }
912
913 public string DownloadString(Uri address)
914 {
915 ArgumentNullException.ThrowIfNull(address, "address");
917 try
918 {
919 WebRequest request;
920 byte[] data = DownloadDataInternal(address, out request);
921 return GetStringUsingEncoding(request, data);
922 }
923 finally
924 {
925 EndOperation();
926 }
927 }
928
929 private static void AbortRequest(WebRequest request)
930 {
931 try
932 {
933 request?.Abort();
934 }
935 catch (Exception ex) when (!(ex is OutOfMemoryException))
936 {
937 }
938 }
939
940 private void CopyHeadersTo(WebRequest request)
941 {
942 if (_headers != null && request is HttpWebRequest httpWebRequest)
943 {
944 string text = _headers["Accept"];
945 string text2 = _headers["Connection"];
946 string text3 = _headers["Content-Type"];
947 string text4 = _headers["Expect"];
948 string text5 = _headers["Referer"];
949 string text6 = _headers["User-Agent"];
950 string text7 = _headers["Host"];
951 _headers.Remove("Accept");
952 _headers.Remove("Connection");
953 _headers.Remove("Content-Type");
954 _headers.Remove("Expect");
955 _headers.Remove("Referer");
956 _headers.Remove("User-Agent");
957 _headers.Remove("Host");
958 request.Headers = _headers;
959 if (!string.IsNullOrEmpty(text))
960 {
961 httpWebRequest.Accept = text;
962 }
963 if (!string.IsNullOrEmpty(text2))
964 {
965 httpWebRequest.Connection = text2;
966 }
967 if (!string.IsNullOrEmpty(text3))
968 {
969 httpWebRequest.ContentType = text3;
970 }
971 if (!string.IsNullOrEmpty(text4))
972 {
973 httpWebRequest.Expect = text4;
974 }
975 if (!string.IsNullOrEmpty(text5))
976 {
977 httpWebRequest.Referer = text5;
978 }
979 if (!string.IsNullOrEmpty(text6))
980 {
981 httpWebRequest.UserAgent = text6;
982 }
983 if (!string.IsNullOrEmpty(text7))
984 {
985 httpWebRequest.Host = text7;
986 }
987 }
988 }
989
990 private Uri GetUri(string address)
991 {
992 ArgumentNullException.ThrowIfNull(address, "address");
993 Uri result;
994 if (_baseAddress != null)
995 {
996 if (!Uri.TryCreate(_baseAddress, address, out result))
997 {
998 return new Uri(Path.GetFullPath(address));
999 }
1000 }
1001 else if (!Uri.TryCreate(address, UriKind.Absolute, out result))
1002 {
1003 return new Uri(Path.GetFullPath(address));
1004 }
1005 return GetUri(result);
1006 }
1007
1008 private Uri GetUri(Uri address)
1009 {
1010 ArgumentNullException.ThrowIfNull(address, "address");
1011 Uri result = address;
1012 if (!address.IsAbsoluteUri && _baseAddress != null && !Uri.TryCreate(_baseAddress, address, out result))
1013 {
1014 return address;
1015 }
1016 if (string.IsNullOrEmpty(result.Query) && _requestParameters != null)
1017 {
1018 StringBuilder stringBuilder = new StringBuilder();
1019 string value = string.Empty;
1020 for (int i = 0; i < _requestParameters.Count; i++)
1021 {
1022 stringBuilder.Append(value).Append(_requestParameters.AllKeys[i]).Append('=')
1024 value = "&";
1025 }
1026 result = new UriBuilder(result)
1027 {
1028 Query = stringBuilder.ToString()
1029 }.Uri;
1030 }
1031 return result;
1032 }
1033
1034 private byte[] DownloadBits(WebRequest request, Stream writeStream)
1035 {
1036 try
1037 {
1038 WebResponse webResponse = (_webResponse = GetWebResponse(request));
1039 long contentLength = webResponse.ContentLength;
1040 byte[] array = new byte[(contentLength == -1 || contentLength > 65536) ? 65536 : contentLength];
1041 if (writeStream is ChunkedMemoryStream)
1042 {
1043 if (contentLength > int.MaxValue)
1044 {
1046 }
1047 writeStream.SetLength(array.Length);
1048 }
1049 using (Stream stream = webResponse.GetResponseStream())
1050 {
1051 if (stream != null)
1052 {
1053 int count;
1054 while ((count = stream.Read(array, 0, array.Length)) != 0)
1055 {
1056 writeStream.Write(array, 0, count);
1057 }
1058 }
1059 }
1060 return (writeStream as ChunkedMemoryStream)?.ToArray();
1061 }
1062 catch (Exception ex) when (!(ex is OutOfMemoryException))
1063 {
1064 writeStream?.Close();
1065 AbortRequest(request);
1066 if (ex is WebException || ex is SecurityException)
1067 {
1068 throw;
1069 }
1070 throw new WebException(System.SR.net_webclient, ex);
1071 }
1072 }
1073
1074 private async void DownloadBitsAsync(WebRequest request, Stream writeStream, AsyncOperation asyncOp, Action<byte[], Exception, AsyncOperation> completionDelegate)
1075 {
1076 Exception exception = null;
1077 try
1078 {
1079 WebResponse webResponse = (_webResponse = await GetWebResponseTaskAsync(request).ConfigureAwait(continueOnCapturedContext: false));
1080 long contentLength = webResponse.ContentLength;
1081 byte[] copyBuffer = new byte[(contentLength == -1 || contentLength > 65536) ? 65536 : contentLength];
1082 if (writeStream is ChunkedMemoryStream)
1083 {
1084 if (contentLength > int.MaxValue)
1085 {
1087 }
1088 writeStream.SetLength(copyBuffer.Length);
1089 }
1090 if (contentLength >= 0)
1091 {
1092 _progress.TotalBytesToReceive = contentLength;
1093 }
1094 using (writeStream)
1095 {
1096 using Stream readStream = webResponse.GetResponseStream();
1097 if (readStream != null)
1098 {
1099 while (true)
1100 {
1101 int num = await readStream.ReadAsync(new Memory<byte>(copyBuffer)).ConfigureAwait(continueOnCapturedContext: false);
1102 if (num == 0)
1103 {
1104 break;
1105 }
1106 _progress.BytesReceived += num;
1108 {
1110 }
1111 await writeStream.WriteAsync(new ReadOnlyMemory<byte>(copyBuffer, 0, num)).ConfigureAwait(continueOnCapturedContext: false);
1112 }
1113 }
1115 {
1116 _progress.TotalBytesToReceive = _progress.BytesReceived;
1117 }
1119 }
1120 completionDelegate((writeStream as ChunkedMemoryStream)?.ToArray(), null, asyncOp);
1121 }
1122 catch (Exception ex) when (!(ex is OutOfMemoryException))
1123 {
1125 AbortRequest(request);
1126 writeStream?.Close();
1127 }
1128 finally
1129 {
1130 if (exception != null)
1131 {
1132 completionDelegate(null, exception, asyncOp);
1133 }
1134 }
1135 }
1136
1137 private byte[] UploadBits(WebRequest request, Stream readStream, byte[] buffer, int chunkSize, byte[] header, byte[] footer)
1138 {
1139 try
1140 {
1141 if (request.RequestUri.Scheme == Uri.UriSchemeFile)
1142 {
1143 header = (footer = null);
1144 }
1145 using (Stream stream = request.GetRequestStream())
1146 {
1147 if (header != null)
1148 {
1149 stream.Write(header, 0, header.Length);
1150 }
1151 if (readStream != null)
1152 {
1153 using (readStream)
1154 {
1155 while (true)
1156 {
1157 int num = readStream.Read(buffer, 0, buffer.Length);
1158 if (num > 0)
1159 {
1160 stream.Write(buffer, 0, num);
1161 continue;
1162 }
1163 break;
1164 }
1165 }
1166 }
1167 else
1168 {
1169 int num2;
1170 for (int i = 0; i < buffer.Length; i += num2)
1171 {
1172 num2 = buffer.Length - i;
1173 if (chunkSize != 0 && num2 > chunkSize)
1174 {
1175 num2 = chunkSize;
1176 }
1177 stream.Write(buffer, i, num2);
1178 }
1179 }
1180 if (footer != null)
1181 {
1182 stream.Write(footer, 0, footer.Length);
1183 }
1184 }
1185 return DownloadBits(request, new ChunkedMemoryStream());
1186 }
1187 catch (Exception ex) when (!(ex is OutOfMemoryException))
1188 {
1189 AbortRequest(request);
1190 if (ex is WebException || ex is SecurityException)
1191 {
1192 throw;
1193 }
1194 throw new WebException(System.SR.net_webclient, ex);
1195 }
1196 }
1197
1198 private async void UploadBitsAsync(WebRequest request, Stream readStream, byte[] buffer, int chunkSize, byte[] header, byte[] footer, AsyncOperation asyncOp, Action<byte[], Exception, AsyncOperation> completionDelegate)
1199 {
1200 _progress.HasUploadPhase = true;
1201 Exception exception = null;
1202 try
1203 {
1204 if (request.RequestUri.Scheme == Uri.UriSchemeFile)
1205 {
1206 byte[] array;
1207 footer = (array = null);
1208 header = array;
1209 }
1210 using (Stream writeStream = await request.GetRequestStreamAsync().ConfigureAwait(continueOnCapturedContext: false))
1211 {
1212 if (header != null)
1213 {
1214 await writeStream.WriteAsync(new ReadOnlyMemory<byte>(header)).ConfigureAwait(continueOnCapturedContext: false);
1215 _progress.BytesSent += header.Length;
1217 }
1218 if (readStream != null)
1219 {
1220 using (readStream)
1221 {
1222 while (true)
1223 {
1224 int bytesRead2 = await readStream.ReadAsync(new Memory<byte>(buffer)).ConfigureAwait(continueOnCapturedContext: false);
1225 if (bytesRead2 <= 0)
1226 {
1227 break;
1228 }
1229 await writeStream.WriteAsync(new ReadOnlyMemory<byte>(buffer, 0, bytesRead2)).ConfigureAwait(continueOnCapturedContext: false);
1230 _progress.BytesSent += bytesRead2;
1232 }
1233 }
1234 }
1235 else
1236 {
1237 int bytesRead2 = 0;
1238 while (bytesRead2 < buffer.Length)
1239 {
1240 int toWrite = buffer.Length - bytesRead2;
1241 if (chunkSize != 0 && toWrite > chunkSize)
1242 {
1243 toWrite = chunkSize;
1244 }
1245 await writeStream.WriteAsync(new ReadOnlyMemory<byte>(buffer, bytesRead2, toWrite)).ConfigureAwait(continueOnCapturedContext: false);
1246 bytesRead2 += toWrite;
1247 _progress.BytesSent += toWrite;
1249 }
1250 }
1251 if (footer != null)
1252 {
1253 await writeStream.WriteAsync(new ReadOnlyMemory<byte>(footer)).ConfigureAwait(continueOnCapturedContext: false);
1254 _progress.BytesSent += footer.Length;
1256 }
1257 }
1258 DownloadBitsAsync(request, new ChunkedMemoryStream(), asyncOp, completionDelegate);
1259 }
1260 catch (Exception ex) when (!(ex is OutOfMemoryException))
1261 {
1263 AbortRequest(request);
1264 }
1265 finally
1266 {
1267 if (exception != null)
1268 {
1269 completionDelegate(null, exception, asyncOp);
1270 }
1271 }
1272 }
1273
1274 private static bool ByteArrayHasPrefix(byte[] prefix, byte[] byteArray)
1275 {
1276 if (prefix == null || byteArray == null || prefix.Length > byteArray.Length)
1277 {
1278 return false;
1279 }
1280 for (int i = 0; i < prefix.Length; i++)
1281 {
1282 if (prefix[i] != byteArray[i])
1283 {
1284 return false;
1285 }
1286 }
1287 return true;
1288 }
1289
1290 private string GetStringUsingEncoding(WebRequest request, byte[] data)
1291 {
1292 Encoding encoding = null;
1293 int num = -1;
1294 string text;
1295 try
1296 {
1297 text = request.ContentType;
1298 }
1299 catch (Exception ex) when (ex is NotImplementedException || ex is NotSupportedException)
1300 {
1301 text = null;
1302 }
1303 if (text != null)
1304 {
1305 text = text.ToLowerInvariant();
1306 string[] array = text.Split(s_parseContentTypeSeparators);
1307 bool flag = false;
1308 string[] array2 = array;
1309 foreach (string text2 in array2)
1310 {
1311 if (text2 == "charset")
1312 {
1313 flag = true;
1314 }
1315 else if (flag)
1316 {
1317 try
1318 {
1319 encoding = System.Text.Encoding.GetEncoding(text2);
1320 }
1321 catch (ArgumentException)
1322 {
1323 break;
1324 }
1325 }
1326 }
1327 }
1328 if (encoding == null)
1329 {
1330 Encoding[] array3 = s_knownEncodings;
1331 for (int j = 0; j < array3.Length; j++)
1332 {
1333 byte[] preamble = array3[j].GetPreamble();
1334 if (ByteArrayHasPrefix(preamble, data))
1335 {
1336 encoding = array3[j];
1337 num = preamble.Length;
1338 break;
1339 }
1340 }
1341 }
1342 if (encoding == null)
1343 {
1344 encoding = Encoding;
1345 }
1346 if (num == -1)
1347 {
1348 byte[] preamble2 = encoding.GetPreamble();
1349 num = (ByteArrayHasPrefix(preamble2, data) ? preamble2.Length : 0);
1350 }
1351 return encoding.GetString(data, num, data.Length - num);
1352 }
1353
1354 private string MapToDefaultMethod(Uri address)
1355 {
1356 Uri uri = ((!address.IsAbsoluteUri && _baseAddress != null) ? new Uri(_baseAddress, address) : address);
1357 if (!string.Equals(uri.Scheme, Uri.UriSchemeFtp, StringComparison.Ordinal))
1358 {
1359 return "POST";
1360 }
1361 return "STOR";
1362 }
1363
1364 [return: NotNullIfNotNull("str")]
1365 private static string UrlEncode(string str)
1366 {
1367 if (str == null)
1368 {
1369 return null;
1370 }
1371 byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
1372 return System.Text.Encoding.ASCII.GetString(UrlEncodeBytesToBytesInternal(bytes, 0, bytes.Length, alwaysCreateReturnValue: false));
1373 }
1374
1375 private static byte[] UrlEncodeBytesToBytesInternal(byte[] bytes, int offset, int count, bool alwaysCreateReturnValue)
1376 {
1377 int num = 0;
1378 int num2 = 0;
1379 for (int i = 0; i < count; i++)
1380 {
1381 char c = (char)bytes[offset + i];
1382 if (c == ' ')
1383 {
1384 num++;
1385 }
1386 else if (!IsSafe(c))
1387 {
1388 num2++;
1389 }
1390 }
1391 if (!alwaysCreateReturnValue && num == 0 && num2 == 0)
1392 {
1393 return bytes;
1394 }
1395 byte[] array = new byte[count + num2 * 2];
1396 int num3 = 0;
1397 for (int j = 0; j < count; j++)
1398 {
1399 byte b = bytes[offset + j];
1400 char c2 = (char)b;
1401 if (IsSafe(c2))
1402 {
1403 array[num3++] = b;
1404 continue;
1405 }
1406 if (c2 == ' ')
1407 {
1408 array[num3++] = 43;
1409 continue;
1410 }
1411 array[num3++] = 37;
1412 array[num3++] = (byte)System.HexConverter.ToCharLower(b >> 4);
1413 array[num3++] = (byte)System.HexConverter.ToCharLower(b);
1414 }
1415 return array;
1416 }
1417
1418 private static bool IsSafe(char ch)
1419 {
1420 if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))
1421 {
1422 return true;
1423 }
1424 switch (ch)
1425 {
1426 case '!':
1427 case '\'':
1428 case '(':
1429 case ')':
1430 case '*':
1431 case '-':
1432 case '.':
1433 case '_':
1434 return true;
1435 default:
1436 return false;
1437 }
1438 }
1439
1440 private void InvokeOperationCompleted(AsyncOperation asyncOp, SendOrPostCallback callback, AsyncCompletedEventArgs eventArgs)
1441 {
1442 if (Interlocked.CompareExchange(ref _asyncOp, null, asyncOp) == asyncOp)
1443 {
1444 EndOperation();
1445 asyncOp.PostOperationCompleted(callback, eventArgs);
1446 }
1447 }
1448
1449 public void OpenReadAsync(Uri address)
1450 {
1451 OpenReadAsync(address, null);
1452 }
1453
1454 public void OpenReadAsync(Uri address, object? userToken)
1455 {
1456 ArgumentNullException.ThrowIfNull(address, "address");
1457 AsyncOperation asyncOp = StartAsyncOperation(userToken);
1458 try
1459 {
1460 WebRequest request = (_webRequest = GetWebRequest(GetUri(address)));
1461 request.BeginGetResponse(delegate(IAsyncResult iar)
1462 {
1463 Stream result = null;
1464 Exception exception = null;
1465 try
1466 {
1467 result = (_webResponse = GetWebResponse(request, iar)).GetResponseStream();
1468 }
1469 catch (Exception ex2) when (!(ex2 is OutOfMemoryException))
1470 {
1472 }
1474 }, null);
1475 }
1476 catch (Exception ex) when (!(ex is OutOfMemoryException))
1477 {
1479 }
1480 }
1481
1482 public void OpenWriteAsync(Uri address)
1483 {
1484 OpenWriteAsync(address, null, null);
1485 }
1486
1487 public void OpenWriteAsync(Uri address, string? method)
1488 {
1489 OpenWriteAsync(address, method, null);
1490 }
1491
1492 public void OpenWriteAsync(Uri address, string? method, object? userToken)
1493 {
1494 ArgumentNullException.ThrowIfNull(address, "address");
1495 if (method == null)
1496 {
1497 method = MapToDefaultMethod(address);
1498 }
1499 AsyncOperation asyncOp = StartAsyncOperation(userToken);
1500 try
1501 {
1502 _method = method;
1503 WebRequest request = (_webRequest = GetWebRequest(GetUri(address)));
1504 request.BeginGetRequestStream(delegate(IAsyncResult iar)
1505 {
1506 WebClientWriteStream result = null;
1507 Exception exception = null;
1508 try
1509 {
1510 result = new WebClientWriteStream(request.EndGetRequestStream(iar), request, this);
1511 }
1512 catch (Exception ex2) when (!(ex2 is OutOfMemoryException))
1513 {
1515 }
1517 }, null);
1518 }
1519 catch (Exception ex) when (!(ex is OutOfMemoryException))
1520 {
1523 }
1524 }
1525
1526 private void DownloadStringAsyncCallback(byte[] returnBytes, Exception exception, object state)
1527 {
1528 AsyncOperation asyncOperation = (AsyncOperation)state;
1529 string result = null;
1530 try
1531 {
1532 if (returnBytes != null)
1533 {
1534 result = GetStringUsingEncoding(_webRequest, returnBytes);
1535 }
1536 }
1537 catch (Exception ex) when (!(ex is OutOfMemoryException))
1538 {
1540 }
1543 }
1544
1545 public void DownloadStringAsync(Uri address)
1546 {
1547 DownloadStringAsync(address, null);
1548 }
1549
1550 public void DownloadStringAsync(Uri address, object? userToken)
1551 {
1552 ArgumentNullException.ThrowIfNull(address, "address");
1553 AsyncOperation asyncOperation = StartAsyncOperation(userToken);
1554 try
1555 {
1557 }
1558 catch (Exception ex) when (!(ex is OutOfMemoryException))
1559 {
1560 DownloadStringAsyncCallback(null, GetExceptionToPropagate(ex), asyncOperation);
1561 }
1562 }
1563
1564 private void DownloadDataAsyncCallback(byte[] returnBytes, Exception exception, object state)
1565 {
1566 AsyncOperation asyncOperation = (AsyncOperation)state;
1569 }
1570
1571 public void DownloadDataAsync(Uri address)
1572 {
1573 DownloadDataAsync(address, null);
1574 }
1575
1576 public void DownloadDataAsync(Uri address, object? userToken)
1577 {
1578 ArgumentNullException.ThrowIfNull(address, "address");
1579 AsyncOperation asyncOperation = StartAsyncOperation(userToken);
1580 try
1581 {
1583 }
1584 catch (Exception ex) when (!(ex is OutOfMemoryException))
1585 {
1586 DownloadDataAsyncCallback(null, GetExceptionToPropagate(ex), asyncOperation);
1587 }
1588 }
1589
1590 private void DownloadFileAsyncCallback(byte[] returnBytes, Exception exception, object state)
1591 {
1592 AsyncOperation asyncOperation = (AsyncOperation)state;
1595 }
1596
1597 public void DownloadFileAsync(Uri address, string fileName)
1598 {
1599 DownloadFileAsync(address, fileName, null);
1600 }
1601
1602 public void DownloadFileAsync(Uri address, string fileName, object? userToken)
1603 {
1604 ArgumentNullException.ThrowIfNull(address, "address");
1605 ArgumentNullException.ThrowIfNull(fileName, "fileName");
1606 FileStream fileStream = null;
1607 AsyncOperation asyncOperation = StartAsyncOperation(userToken);
1608 try
1609 {
1610 fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
1611 DownloadBitsAsync(_webRequest = GetWebRequest(GetUri(address)), fileStream, asyncOperation, DownloadFileAsyncCallback);
1612 }
1613 catch (Exception ex) when (!(ex is OutOfMemoryException))
1614 {
1615 fileStream?.Close();
1616 DownloadFileAsyncCallback(null, GetExceptionToPropagate(ex), asyncOperation);
1617 }
1618 }
1619
1620 public void UploadStringAsync(Uri address, string data)
1621 {
1622 UploadStringAsync(address, null, data, null);
1623 }
1624
1625 public void UploadStringAsync(Uri address, string? method, string data)
1626 {
1627 UploadStringAsync(address, method, data, null);
1628 }
1629
1630 public void UploadStringAsync(Uri address, string? method, string data, object? userToken)
1631 {
1632 ArgumentNullException.ThrowIfNull(address, "address");
1633 ArgumentNullException.ThrowIfNull(data, "data");
1634 if (method == null)
1635 {
1636 method = MapToDefaultMethod(address);
1637 }
1638 AsyncOperation asyncOperation = StartAsyncOperation(userToken);
1639 try
1640 {
1641 byte[] bytes = Encoding.GetBytes(data);
1642 _method = method;
1643 _contentLength = bytes.Length;
1644 UploadBitsAsync(_webRequest = GetWebRequest(GetUri(address)), null, bytes, 0, null, null, asyncOperation, delegate(byte[] bytesResult, Exception error, AsyncOperation uploadAsyncOp)
1645 {
1646 string result = null;
1647 if (error == null && bytesResult != null)
1648 {
1649 try
1650 {
1651 result = GetStringUsingEncoding(_webRequest, bytesResult);
1652 }
1653 catch (Exception ex2) when (!(ex2 is OutOfMemoryException))
1654 {
1655 error = GetExceptionToPropagate(ex2);
1656 }
1657 }
1659 });
1660 }
1661 catch (Exception ex) when (!(ex is OutOfMemoryException))
1662 {
1665 }
1666 }
1667
1668 public void UploadDataAsync(Uri address, byte[] data)
1669 {
1670 UploadDataAsync(address, null, data, null);
1671 }
1672
1673 public void UploadDataAsync(Uri address, string? method, byte[] data)
1674 {
1675 UploadDataAsync(address, method, data, null);
1676 }
1677
1678 public void UploadDataAsync(Uri address, string? method, byte[] data, object? userToken)
1679 {
1680 ArgumentNullException.ThrowIfNull(address, "address");
1681 ArgumentNullException.ThrowIfNull(data, "data");
1682 if (method == null)
1683 {
1684 method = MapToDefaultMethod(address);
1685 }
1686 AsyncOperation asyncOp = StartAsyncOperation(userToken);
1687 try
1688 {
1689 _method = method;
1690 _contentLength = data.Length;
1691 WebRequest request = (_webRequest = GetWebRequest(GetUri(address)));
1692 int chunkSize = 0;
1693 if (this.UploadProgressChanged != null)
1694 {
1695 chunkSize = (int)Math.Min(8192L, data.Length);
1696 }
1697 UploadBitsAsync(request, null, data, chunkSize, null, null, asyncOp, delegate(byte[] result, Exception error, AsyncOperation uploadAsyncOp)
1698 {
1700 });
1701 }
1702 catch (Exception ex) when (!(ex is OutOfMemoryException))
1703 {
1706 }
1707 }
1708
1709 public void UploadFileAsync(Uri address, string fileName)
1710 {
1711 UploadFileAsync(address, null, fileName, null);
1712 }
1713
1714 public void UploadFileAsync(Uri address, string? method, string fileName)
1715 {
1716 UploadFileAsync(address, method, fileName, null);
1717 }
1718
1719 public void UploadFileAsync(Uri address, string? method, string fileName, object? userToken)
1720 {
1721 ArgumentNullException.ThrowIfNull(address, "address");
1722 ArgumentNullException.ThrowIfNull(fileName, "fileName");
1723 if (method == null)
1724 {
1725 method = MapToDefaultMethod(address);
1726 }
1727 FileStream fs = null;
1728 AsyncOperation asyncOp = StartAsyncOperation(userToken);
1729 try
1730 {
1731 _method = method;
1732 byte[] formHeaderBytes = null;
1733 byte[] boundaryBytes = null;
1734 byte[] buffer = null;
1735 Uri uri = GetUri(address);
1736 bool needsHeaderAndBoundary = uri.Scheme != Uri.UriSchemeFile;
1737 OpenFileInternal(needsHeaderAndBoundary, fileName, out fs, out buffer, ref formHeaderBytes, ref boundaryBytes);
1738 UploadBitsAsync(_webRequest = GetWebRequest(uri), fs, buffer, 0, formHeaderBytes, boundaryBytes, asyncOp, delegate(byte[] result, Exception error, AsyncOperation uploadAsyncOp)
1739 {
1741 });
1742 }
1743 catch (Exception ex) when (!(ex is OutOfMemoryException))
1744 {
1745 fs?.Close();
1748 }
1749 }
1750
1751 public void UploadValuesAsync(Uri address, NameValueCollection data)
1752 {
1753 UploadValuesAsync(address, null, data, null);
1754 }
1755
1756 public void UploadValuesAsync(Uri address, string? method, NameValueCollection data)
1757 {
1758 UploadValuesAsync(address, method, data, null);
1759 }
1760
1761 public void UploadValuesAsync(Uri address, string? method, NameValueCollection data, object? userToken)
1762 {
1763 ArgumentNullException.ThrowIfNull(address, "address");
1764 ArgumentNullException.ThrowIfNull(data, "data");
1765 if (method == null)
1766 {
1767 method = MapToDefaultMethod(address);
1768 }
1769 AsyncOperation asyncOp = StartAsyncOperation(userToken);
1770 try
1771 {
1772 byte[] valuesToUpload = GetValuesToUpload(data);
1773 _method = method;
1774 WebRequest request = (_webRequest = GetWebRequest(GetUri(address)));
1775 int chunkSize = 0;
1776 if (this.UploadProgressChanged != null)
1777 {
1778 chunkSize = (int)Math.Min(8192L, valuesToUpload.Length);
1779 }
1780 UploadBitsAsync(request, null, valuesToUpload, chunkSize, null, null, asyncOp, delegate(byte[] result, Exception error, AsyncOperation uploadAsyncOp)
1781 {
1783 });
1784 }
1785 catch (Exception ex) when (!(ex is OutOfMemoryException))
1786 {
1789 }
1790 }
1791
1793 {
1794 if (!(e is WebException) && !(e is SecurityException))
1795 {
1796 return new WebException(System.SR.net_webclient, e);
1797 }
1798 return e;
1799 }
1800
1801 public void CancelAsync()
1802 {
1803 WebRequest webRequest = _webRequest;
1804 _canceled = true;
1805 AbortRequest(webRequest);
1806 }
1807
1809 {
1810 return DownloadStringTaskAsync(GetUri(address));
1811 }
1812
1814 {
1817 handler = delegate(object sender, DownloadStringCompletedEventArgs e)
1818 {
1819 HandleCompletion(tcs, e, (DownloadStringCompletedEventArgs args) => args.Result, handler, delegate(WebClient webClient, DownloadStringCompletedEventHandler completion)
1820 {
1821 webClient.DownloadStringCompleted -= completion;
1822 });
1823 };
1824 DownloadStringCompleted += handler;
1825 try
1826 {
1827 DownloadStringAsync(address, tcs);
1828 }
1829 catch
1830 {
1831 DownloadStringCompleted -= handler;
1832 throw;
1833 }
1834 return tcs.Task;
1835 }
1836
1837 public Task<Stream> OpenReadTaskAsync(string address)
1838 {
1839 return OpenReadTaskAsync(GetUri(address));
1840 }
1841
1843 {
1845 OpenReadCompletedEventHandler handler = null;
1846 handler = delegate(object sender, OpenReadCompletedEventArgs e)
1847 {
1848 HandleCompletion(tcs, e, (OpenReadCompletedEventArgs args) => args.Result, handler, delegate(WebClient webClient, OpenReadCompletedEventHandler completion)
1849 {
1850 webClient.OpenReadCompleted -= completion;
1851 });
1852 };
1853 OpenReadCompleted += handler;
1854 try
1855 {
1856 OpenReadAsync(address, tcs);
1857 }
1858 catch
1859 {
1860 OpenReadCompleted -= handler;
1861 throw;
1862 }
1863 return tcs.Task;
1864 }
1865
1866 public Task<Stream> OpenWriteTaskAsync(string address)
1867 {
1868 return OpenWriteTaskAsync(GetUri(address), null);
1869 }
1870
1872 {
1873 return OpenWriteTaskAsync(address, null);
1874 }
1875
1876 public Task<Stream> OpenWriteTaskAsync(string address, string? method)
1877 {
1878 return OpenWriteTaskAsync(GetUri(address), method);
1879 }
1880
1881 public Task<Stream> OpenWriteTaskAsync(Uri address, string? method)
1882 {
1884 OpenWriteCompletedEventHandler handler = null;
1885 handler = delegate(object sender, OpenWriteCompletedEventArgs e)
1886 {
1887 HandleCompletion(tcs, e, (OpenWriteCompletedEventArgs args) => args.Result, handler, delegate(WebClient webClient, OpenWriteCompletedEventHandler completion)
1888 {
1889 webClient.OpenWriteCompleted -= completion;
1890 });
1891 };
1892 OpenWriteCompleted += handler;
1893 try
1894 {
1895 OpenWriteAsync(address, method, tcs);
1896 }
1897 catch
1898 {
1899 OpenWriteCompleted -= handler;
1900 throw;
1901 }
1902 return tcs.Task;
1903 }
1904
1905 public Task<string> UploadStringTaskAsync(string address, string data)
1906 {
1907 return UploadStringTaskAsync(address, null, data);
1908 }
1909
1910 public Task<string> UploadStringTaskAsync(Uri address, string data)
1911 {
1912 return UploadStringTaskAsync(address, null, data);
1913 }
1914
1915 public Task<string> UploadStringTaskAsync(string address, string? method, string data)
1916 {
1917 return UploadStringTaskAsync(GetUri(address), method, data);
1918 }
1919
1920 public Task<string> UploadStringTaskAsync(Uri address, string? method, string data)
1921 {
1923 UploadStringCompletedEventHandler handler = null;
1924 handler = delegate(object sender, UploadStringCompletedEventArgs e)
1925 {
1926 HandleCompletion(tcs, e, (UploadStringCompletedEventArgs args) => args.Result, handler, delegate(WebClient webClient, UploadStringCompletedEventHandler completion)
1927 {
1928 webClient.UploadStringCompleted -= completion;
1929 });
1930 };
1931 UploadStringCompleted += handler;
1932 try
1933 {
1934 UploadStringAsync(address, method, data, tcs);
1935 }
1936 catch
1937 {
1938 UploadStringCompleted -= handler;
1939 throw;
1940 }
1941 return tcs.Task;
1942 }
1943
1945 {
1946 return DownloadDataTaskAsync(GetUri(address));
1947 }
1948
1950 {
1952 DownloadDataCompletedEventHandler handler = null;
1953 handler = delegate(object sender, DownloadDataCompletedEventArgs e)
1954 {
1955 HandleCompletion(tcs, e, (DownloadDataCompletedEventArgs args) => args.Result, handler, delegate(WebClient webClient, DownloadDataCompletedEventHandler completion)
1956 {
1957 webClient.DownloadDataCompleted -= completion;
1958 });
1959 };
1960 DownloadDataCompleted += handler;
1961 try
1962 {
1963 DownloadDataAsync(address, tcs);
1964 }
1965 catch
1966 {
1967 DownloadDataCompleted -= handler;
1968 throw;
1969 }
1970 return tcs.Task;
1971 }
1972
1973 public Task DownloadFileTaskAsync(string address, string fileName)
1974 {
1975 return DownloadFileTaskAsync(GetUri(address), fileName);
1976 }
1977
1978 public Task DownloadFileTaskAsync(Uri address, string fileName)
1979 {
1981 AsyncCompletedEventHandler handler = null;
1982 handler = delegate(object sender, AsyncCompletedEventArgs e)
1983 {
1984 HandleCompletion(tcs, e, (AsyncCompletedEventArgs args) => (object)null, handler, delegate(WebClient webClient, AsyncCompletedEventHandler completion)
1985 {
1986 webClient.DownloadFileCompleted -= completion;
1987 });
1988 };
1989 DownloadFileCompleted += handler;
1990 try
1991 {
1992 DownloadFileAsync(address, fileName, tcs);
1993 }
1994 catch
1995 {
1996 DownloadFileCompleted -= handler;
1997 throw;
1998 }
1999 return tcs.Task;
2000 }
2001
2002 public Task<byte[]> UploadDataTaskAsync(string address, byte[] data)
2003 {
2004 return UploadDataTaskAsync(GetUri(address), null, data);
2005 }
2006
2007 public Task<byte[]> UploadDataTaskAsync(Uri address, byte[] data)
2008 {
2009 return UploadDataTaskAsync(address, null, data);
2010 }
2011
2012 public Task<byte[]> UploadDataTaskAsync(string address, string? method, byte[] data)
2013 {
2014 return UploadDataTaskAsync(GetUri(address), method, data);
2015 }
2016
2017 public Task<byte[]> UploadDataTaskAsync(Uri address, string? method, byte[] data)
2018 {
2020 UploadDataCompletedEventHandler handler = null;
2021 handler = delegate(object sender, UploadDataCompletedEventArgs e)
2022 {
2023 HandleCompletion(tcs, e, (UploadDataCompletedEventArgs args) => args.Result, handler, delegate(WebClient webClient, UploadDataCompletedEventHandler completion)
2024 {
2025 webClient.UploadDataCompleted -= completion;
2026 });
2027 };
2028 UploadDataCompleted += handler;
2029 try
2030 {
2031 UploadDataAsync(address, method, data, tcs);
2032 }
2033 catch
2034 {
2035 UploadDataCompleted -= handler;
2036 throw;
2037 }
2038 return tcs.Task;
2039 }
2040
2041 public Task<byte[]> UploadFileTaskAsync(string address, string fileName)
2042 {
2043 return UploadFileTaskAsync(GetUri(address), null, fileName);
2044 }
2045
2046 public Task<byte[]> UploadFileTaskAsync(Uri address, string fileName)
2047 {
2048 return UploadFileTaskAsync(address, null, fileName);
2049 }
2050
2051 public Task<byte[]> UploadFileTaskAsync(string address, string? method, string fileName)
2052 {
2053 return UploadFileTaskAsync(GetUri(address), method, fileName);
2054 }
2055
2056 public Task<byte[]> UploadFileTaskAsync(Uri address, string? method, string fileName)
2057 {
2059 UploadFileCompletedEventHandler handler = null;
2060 handler = delegate(object sender, UploadFileCompletedEventArgs e)
2061 {
2062 HandleCompletion(tcs, e, (UploadFileCompletedEventArgs args) => args.Result, handler, delegate(WebClient webClient, UploadFileCompletedEventHandler completion)
2063 {
2064 webClient.UploadFileCompleted -= completion;
2065 });
2066 };
2067 UploadFileCompleted += handler;
2068 try
2069 {
2070 UploadFileAsync(address, method, fileName, tcs);
2071 }
2072 catch
2073 {
2074 UploadFileCompleted -= handler;
2075 throw;
2076 }
2077 return tcs.Task;
2078 }
2079
2081 {
2082 return UploadValuesTaskAsync(GetUri(address), null, data);
2083 }
2084
2085 public Task<byte[]> UploadValuesTaskAsync(string address, string? method, NameValueCollection data)
2086 {
2087 return UploadValuesTaskAsync(GetUri(address), method, data);
2088 }
2089
2091 {
2092 return UploadValuesTaskAsync(address, null, data);
2093 }
2094
2095 public Task<byte[]> UploadValuesTaskAsync(Uri address, string? method, NameValueCollection data)
2096 {
2098 UploadValuesCompletedEventHandler handler = null;
2099 handler = delegate(object sender, UploadValuesCompletedEventArgs e)
2100 {
2101 HandleCompletion(tcs, e, (UploadValuesCompletedEventArgs args) => args.Result, handler, delegate(WebClient webClient, UploadValuesCompletedEventHandler completion)
2102 {
2103 webClient.UploadValuesCompleted -= completion;
2104 });
2105 };
2106 UploadValuesCompleted += handler;
2107 try
2108 {
2109 UploadValuesAsync(address, method, data, tcs);
2110 }
2111 catch
2112 {
2113 UploadValuesCompleted -= handler;
2114 throw;
2115 }
2116 return tcs.Task;
2117 }
2118
2119 private void HandleCompletion<TAsyncCompletedEventArgs, TCompletionDelegate, T>(TaskCompletionSource<T> tcs, TAsyncCompletedEventArgs e, Func<TAsyncCompletedEventArgs, T> getResult, TCompletionDelegate handler, Action<WebClient, TCompletionDelegate> unregisterHandler) where TAsyncCompletedEventArgs : AsyncCompletedEventArgs
2120 {
2121 if (e.UserState != tcs)
2122 {
2123 return;
2124 }
2125 try
2126 {
2127 unregisterHandler(this, handler);
2128 }
2129 finally
2130 {
2131 if (e.Error != null)
2132 {
2133 tcs.TrySetException(e.Error);
2134 }
2135 else if (e.Cancelled)
2136 {
2137 tcs.TrySetCanceled();
2138 }
2139 else
2140 {
2141 tcs.TrySetResult(getResult(e));
2142 }
2143 }
2144 }
2145
2146 private void PostProgressChanged(AsyncOperation asyncOp, ProgressData progress)
2147 {
2148 if (asyncOp == null || (progress.BytesSent <= 0 && progress.BytesReceived <= 0))
2149 {
2150 return;
2151 }
2152 if (progress.HasUploadPhase)
2153 {
2154 if (this.UploadProgressChanged != null)
2155 {
2156 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));
2157 asyncOp.Post(_reportUploadProgressChanged, new UploadProgressChangedEventArgs(progressPercentage, asyncOp.UserSuppliedState, progress.BytesSent, progress.TotalBytesToSend, progress.BytesReceived, progress.TotalBytesToReceive));
2158 }
2159 }
2160 else if (this.DownloadProgressChanged != null)
2161 {
2162 int progressPercentage = (int)((progress.TotalBytesToReceive >= 0) ? ((progress.TotalBytesToReceive == 0L) ? 100 : (100 * progress.BytesReceived / progress.TotalBytesToReceive)) : 0);
2164 }
2165 }
2166
2167 [Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
2168 [EditorBrowsable(EditorBrowsableState.Never)]
2170 {
2171 }
2172}
static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression("argument")] string? paramName=null)
static AsyncOperation CreateOperation(object? userSuppliedState)
void PostOperationCompleted(SendOrPostCallback d, object? arg)
void Post(SendOrPostCallback d, object? arg)
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static char ToCharLower(int value)
static void Delete(string path)
Definition File.cs:88
static ? string GetFileName(string? path)
Definition Path.cs:200
static string GetFullPath(string path)
Definition Path.cs:881
void SetLength(long value)
virtual void Close()
Definition Stream.cs:644
Task WriteAsync(byte[] buffer, int offset, int count)
Definition Stream.cs:914
int Read(byte[] buffer, int offset, int count)
Task< int > ReadAsync(byte[] buffer, int offset, int count)
Definition Stream.cs:762
void Write(byte[] buffer, int offset, int count)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static ICredentials DefaultCredentials
WebClientWriteStream(Stream stream, WebRequest request, WebClient webClient)
Definition WebClient.cs:43
override void Dispose(bool disposing)
Definition WebClient.cs:50
WebHeaderCollection _headers
Definition WebClient.cs:70
void OpenWriteAsync(Uri address, string? method, object? userToken)
byte[] UploadFile(Uri address, string? method, string fileName)
Definition WebClient.cs:757
SendOrPostCallback _openWriteOperationCompleted
Definition WebClient.cs:102
void UploadFileAsync(Uri address, string? method, string fileName, object? userToken)
string DownloadString(Uri address)
Definition WebClient.cs:913
void DownloadFileAsync(Uri address, string fileName, object? userToken)
void UploadFileAsync(Uri address, string? method, string fileName)
void DownloadDataAsync(Uri address, object? userToken)
void UploadStringAsync(Uri address, string? method, string data, object? userToken)
Task< byte[]> DownloadDataTaskAsync(Uri address)
ICredentials? Credentials
Definition WebClient.cs:173
Stream OpenRead(string address)
Definition WebClient.cs:557
static bool ByteArrayHasPrefix(byte[] prefix, byte[] byteArray)
UploadDataCompletedEventHandler? UploadDataCompleted
Definition WebClient.cs:261
byte[] UploadBits(WebRequest request, Stream readStream, byte[] buffer, int chunkSize, byte[] header, byte[] footer)
Uri GetUri(string address)
Definition WebClient.cs:990
void DownloadDataAsync(Uri address)
void HandleCompletion< TAsyncCompletedEventArgs, TCompletionDelegate, T >(TaskCompletionSource< T > tcs, TAsyncCompletedEventArgs e, Func< TAsyncCompletedEventArgs, T > getResult, TCompletionDelegate handler, Action< WebClient, TCompletionDelegate > unregisterHandler)
async void DownloadBitsAsync(WebRequest request, Stream writeStream, AsyncOperation asyncOp, Action< byte[], Exception, AsyncOperation > completionDelegate)
byte[] GetValuesToUpload(NameValueCollection data)
Definition WebClient.cs:799
Stream OpenWrite(string address, string? method)
Definition WebClient.cs:597
Stream OpenWrite(string address)
Definition WebClient.cs:587
Task< Stream > OpenWriteTaskAsync(string address, string? method)
SendOrPostCallback _uploadValuesOperationCompleted
Definition WebClient.cs:114
void UploadDataAsync(Uri address, string? method, byte[] data)
Task< byte[]> UploadFileTaskAsync(Uri address, string fileName)
SendOrPostCallback _reportUploadProgressChanged
Definition WebClient.cs:118
Task< string > UploadStringTaskAsync(string address, string data)
byte[] UploadDataInternal(Uri address, string method, byte[] data, out WebRequest request)
Definition WebClient.cs:667
Task< byte[]> UploadDataTaskAsync(Uri address, byte[] data)
Task< Stream > OpenReadTaskAsync(Uri address)
Stream OpenWrite(Uri address)
Definition WebClient.cs:592
byte[] UploadFile(string address, string fileName)
Definition WebClient.cs:742
void UploadValuesAsync(Uri address, string? method, NameValueCollection data)
byte[] DownloadBits(WebRequest request, Stream writeStream)
void DownloadFileAsyncCallback(byte[] returnBytes, Exception exception, object state)
byte[] UploadData(Uri address, string? method, byte[] data)
Definition WebClient.cs:647
NameValueCollection QueryString
Definition WebClient.cs:210
string UploadString(Uri address, string? method, string data)
Definition WebClient.cs:886
virtual void OnOpenReadCompleted(OpenReadCompletedEventArgs e)
Definition WebClient.cs:341
void UploadValuesAsync(Uri address, string? method, NameValueCollection data, object? userToken)
Task< string > UploadStringTaskAsync(Uri address, string data)
byte[] DownloadDataInternal(Uri address, out WebRequest request)
Definition WebClient.cs:492
AsyncCompletedEventHandler? DownloadFileCompleted
Definition WebClient.cs:257
virtual WebRequest GetWebRequest(Uri address)
Definition WebClient.cs:428
WebRequest _webRequest
Definition WebClient.cs:76
SendOrPostCallback _downloadFileOperationCompleted
Definition WebClient.cs:106
void OpenReadAsync(Uri address)
void CopyHeadersTo(WebRequest request)
Definition WebClient.cs:940
Task< string > UploadStringTaskAsync(Uri address, string? method, string data)
Task< byte[]> UploadValuesTaskAsync(string address, NameValueCollection data)
SendOrPostCallback _openReadOperationCompleted
Definition WebClient.cs:100
ICredentials _credentials
Definition WebClient.cs:68
AsyncOperation _asyncOp
Definition WebClient.cs:96
Task< byte[]> UploadValuesTaskAsync(Uri address, string? method, NameValueCollection data)
byte[] UploadFile(Uri address, string fileName)
Definition WebClient.cs:747
SendOrPostCallback _uploadFileOperationCompleted
Definition WebClient.cs:112
static readonly char[] s_parseContentTypeSeparators
Definition WebClient.cs:120
SendOrPostCallback _reportDownloadProgressChanged
Definition WebClient.cs:116
void OpenFileInternal(bool needsHeaderAndBoundary, string fileName, out FileStream fs, out byte[] buffer, ref byte[] formHeaderBytes, ref byte[] boundaryBytes)
Definition WebClient.cs:691
static readonly Encoding[] s_knownEncodings
Definition WebClient.cs:122
virtual WebResponse GetWebResponse(WebRequest request, IAsyncResult result)
Definition WebClient.cs:460
byte[] UploadValues(Uri address, string? method, NameValueCollection data)
Definition WebClient.cs:839
SendOrPostCallback _uploadDataOperationCompleted
Definition WebClient.cs:110
ProgressData _progress
Definition WebClient.cs:88
static Exception GetExceptionToPropagate(Exception e)
virtual WebResponse GetWebResponse(WebRequest request)
Definition WebClient.cs:455
Task< byte[]> UploadFileTaskAsync(Uri address, string? method, string fileName)
Task< byte[]> UploadFileTaskAsync(string address, string? method, string fileName)
static byte[] UrlEncodeBytesToBytesInternal(byte[] bytes, int offset, int count, bool alwaysCreateReturnValue)
virtual void OnDownloadDataCompleted(DownloadDataCompletedEventArgs e)
Definition WebClient.cs:301
byte[] UploadFile(string address, string? method, string fileName)
Definition WebClient.cs:752
void DownloadStringAsyncCallback(byte[] returnBytes, Exception exception, object state)
WebResponse _webResponse
Definition WebClient.cs:74
void UploadStringAsync(Uri address, string data)
virtual void OnUploadStringCompleted(UploadStringCompletedEventArgs e)
Definition WebClient.cs:316
virtual void OnOpenWriteCompleted(OpenWriteCompletedEventArgs e)
Definition WebClient.cs:346
string GetStringUsingEncoding(WebRequest request, byte[] data)
static string UrlEncode(string str)
UploadValuesCompletedEventHandler? UploadValuesCompleted
Definition WebClient.cs:265
RequestCachePolicy? CachePolicy
Definition WebClient.cs:241
AsyncOperation StartAsyncOperation(object userToken)
Definition WebClient.cs:366
void OpenWriteAsync(Uri address, string? method)
NameValueCollection _requestParameters
Definition WebClient.cs:72
void UploadDataAsync(Uri address, byte[] data)
DownloadStringCompletedEventHandler? DownloadStringCompleted
Definition WebClient.cs:253
Task< byte[]> UploadDataTaskAsync(Uri address, string? method, byte[] data)
byte[] DownloadData(string address)
Definition WebClient.cs:472
Stream OpenWrite(Uri address, string? method)
Definition WebClient.cs:602
string MapToDefaultMethod(Uri address)
Task< string > DownloadStringTaskAsync(Uri address)
SendOrPostCallback _downloadDataOperationCompleted
Definition WebClient.cs:98
UploadProgressChangedEventHandler? UploadProgressChanged
Definition WebClient.cs:273
string UploadString(string address, string? method, string data)
Definition WebClient.cs:881
Task< string > UploadStringTaskAsync(string address, string? method, string data)
byte[] UploadValues(Uri address, NameValueCollection data)
Definition WebClient.cs:829
void OpenReadAsync(Uri address, object? userToken)
WebHeaderCollection? ResponseHeaders
Definition WebClient.cs:222
void DownloadStringAsync(Uri address, object? userToken)
DownloadDataCompletedEventHandler? DownloadDataCompleted
Definition WebClient.cs:255
Task< byte[]> UploadValuesTaskAsync(string address, string? method, NameValueCollection data)
virtual void OnWriteStreamClosed(WriteStreamClosedEventArgs e)
SendOrPostCallback _uploadStringOperationCompleted
Definition WebClient.cs:108
void DownloadFileAsync(Uri address, string fileName)
Task< byte[]> UploadValuesTaskAsync(Uri address, NameValueCollection data)
Task< Stream > OpenReadTaskAsync(string address)
Task< Stream > OpenWriteTaskAsync(Uri address)
virtual void OnUploadFileCompleted(UploadFileCompletedEventArgs e)
Definition WebClient.cs:326
byte[] UploadData(string address, string? method, byte[] data)
Definition WebClient.cs:642
static void AbortRequest(WebRequest request)
Definition WebClient.cs:929
virtual void OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
Definition WebClient.cs:296
void DownloadFile(Uri address, string fileName)
Definition WebClient.cs:519
SendOrPostCallback _downloadStringOperationCompleted
Definition WebClient.cs:104
string UploadString(Uri address, string data)
Definition WebClient.cs:876
void UploadStringAsync(Uri address, string? method, string data)
static bool IsSafe(char ch)
void InvokeOperationCompleted(AsyncOperation asyncOp, SendOrPostCallback callback, AsyncCompletedEventArgs eventArgs)
Task< string > DownloadStringTaskAsync(string address)
OpenReadCompletedEventHandler? OpenReadCompleted
Definition WebClient.cs:267
virtual void OnUploadValuesCompleted(UploadValuesCompletedEventArgs e)
Definition WebClient.cs:331
WebHeaderCollection Headers
Definition WebClient.cs:197
string UploadString(string address, string data)
Definition WebClient.cs:871
void DownloadDataAsyncCallback(byte[] returnBytes, Exception exception, object state)
Task< Stream > OpenWriteTaskAsync(Uri address, string? method)
OpenWriteCompletedEventHandler? OpenWriteCompleted
Definition WebClient.cs:269
void DownloadStringAsync(Uri address)
Task< Stream > OpenWriteTaskAsync(string address)
void DownloadFile(string address, string fileName)
Definition WebClient.cs:514
Stream OpenRead(Uri address)
Definition WebClient.cs:562
void UploadValuesAsync(Uri address, NameValueCollection data)
async Task< WebResponse > GetWebResponseTaskAsync(WebRequest request)
Definition WebClient.cs:465
virtual void OnDownloadProgressChanged(DownloadProgressChangedEventArgs e)
Definition WebClient.cs:311
virtual void OnDownloadFileCompleted(AsyncCompletedEventArgs e)
Definition WebClient.cs:306
Task< byte[]> UploadDataTaskAsync(string address, byte[] data)
WriteStreamClosedEventHandler? WriteStreamClosed
Definition WebClient.cs:278
void OpenWriteAsync(Uri address)
UploadFileCompletedEventHandler? UploadFileCompleted
Definition WebClient.cs:263
void PostProgressChanged(AsyncOperation asyncOp, ProgressData progress)
string DownloadString(string address)
Definition WebClient.cs:908
byte[] UploadValues(string address, NameValueCollection data)
Definition WebClient.cs:824
virtual void OnUploadDataCompleted(UploadDataCompletedEventArgs e)
Definition WebClient.cs:321
byte[] UploadValues(string address, string? method, NameValueCollection data)
Definition WebClient.cs:834
DownloadProgressChangedEventHandler? DownloadProgressChanged
Definition WebClient.cs:271
Uri GetUri(Uri address)
virtual void OnUploadProgressChanged(UploadProgressChangedEventArgs e)
Definition WebClient.cs:336
Task< byte[]> UploadFileTaskAsync(string address, string fileName)
UploadStringCompletedEventHandler? UploadStringCompleted
Definition WebClient.cs:259
Task DownloadFileTaskAsync(string address, string fileName)
Task< byte[]> DownloadDataTaskAsync(string address)
void UploadDataAsync(Uri address, string? method, byte[] data, object? userToken)
async void UploadBitsAsync(WebRequest request, Stream readStream, byte[] buffer, int chunkSize, byte[] header, byte[] footer, AsyncOperation asyncOp, Action< byte[], Exception, AsyncOperation > completionDelegate)
Task DownloadFileTaskAsync(Uri address, string fileName)
byte[] UploadData(string address, byte[] data)
Definition WebClient.cs:632
byte[] UploadData(Uri address, byte[] data)
Definition WebClient.cs:637
Task< byte[]> UploadDataTaskAsync(string address, string? method, byte[] data)
void UploadFileAsync(Uri address, string fileName)
byte[] DownloadData(Uri address)
Definition WebClient.cs:477
void Remove(HttpRequestHeader header)
static ? IWebProxy DefaultWebProxy
virtual IAsyncResult BeginGetResponse(AsyncCallback? callback, object? state)
static WebRequest Create(Uri requestUri, bool useUriBase)
virtual void Abort()
virtual ? string ContentType
virtual WebResponse EndGetResponse(IAsyncResult asyncResult)
virtual Uri RequestUri
virtual Task< Stream > GetRequestStreamAsync()
virtual WebResponse GetResponse()
virtual Stream GetRequestStream()
virtual Stream EndGetRequestStream(IAsyncResult asyncResult)
virtual IAsyncResult BeginGetRequestStream(AsyncCallback? callback, object? state)
virtual Stream GetResponseStream()
virtual long ContentLength
Definition WebResponse.cs:9
virtual WebHeaderCollection Headers
static string net_webclient
Definition SR.cs:14
static string net_webclient_ContentType
Definition SR.cs:16
static string net_webclient_Multipart
Definition SR.cs:18
static string net_webclient_invalid_baseaddress
Definition SR.cs:22
static string net_webstatus_MessageLengthLimitExceeded
Definition SR.cs:24
static string net_webclient_no_concurrent_io_allowed
Definition SR.cs:20
Definition SR.cs:7
static Encoding Unicode
Definition Encoding.cs:519
static Encoding UTF8
Definition Encoding.cs:526
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
static Encoding UTF32
Definition Encoding.cs:528
static Encoding ASCII
Definition Encoding.cs:511
virtual byte[] GetBytes(char[] chars)
Definition Encoding.cs:781
static Encoding Default
Definition Encoding.cs:345
virtual byte[] GetPreamble()
Definition Encoding.cs:689
unsafe string GetString(byte *bytes, int byteCount)
Definition Encoding.cs:973
override string ToString()
StringBuilder Append(char value, int repeatCount)
static int CompareExchange(ref int location1, int value, int comparand)
static int Decrement(ref int location)
static int Increment(ref int location)
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
static bool Read(ref bool location)
Definition Volatile.cs:67
static bool TryCreate([NotNullWhen(true)] string? uriString, UriKind uriKind, [NotNullWhen(true)] out Uri? result)
Definition Uri.cs:3793
static readonly string UriSchemeFtp
Definition Uri.cs:157
string Query
Definition Uri.cs:477
static readonly string UriSchemeFile
Definition Uri.cs:155
bool IsAbsoluteUri
Definition Uri.cs:572
override string ToString()
Definition Uri.cs:1119
string Scheme
Definition Uri.cs:505
delegate void AsyncCompletedEventHandler(object? sender, AsyncCompletedEventArgs e)
delegate void DownloadProgressChangedEventHandler(object sender, DownloadProgressChangedEventArgs e)
delegate void DownloadStringCompletedEventHandler(object sender, DownloadStringCompletedEventArgs e)
delegate void UploadStringCompletedEventHandler(object sender, UploadStringCompletedEventArgs e)
delegate void UploadDataCompletedEventHandler(object sender, UploadDataCompletedEventArgs e)
delegate void UploadFileCompletedEventHandler(object sender, UploadFileCompletedEventArgs e)
delegate void DownloadDataCompletedEventHandler(object sender, DownloadDataCompletedEventArgs e)
delegate void OpenWriteCompletedEventHandler(object sender, OpenWriteCompletedEventArgs e)
delegate void OpenReadCompletedEventHandler(object sender, OpenReadCompletedEventArgs e)
delegate void UploadValuesCompletedEventHandler(object sender, UploadValuesCompletedEventArgs e)
delegate void WriteStreamClosedEventHandler(object sender, WriteStreamClosedEventArgs e)
delegate void UploadProgressChangedEventHandler(object sender, UploadProgressChangedEventArgs e)
UriKind
Definition UriKind.cs:4