50 protected override void Dispose(
bool disposing)
61 base.Dispose(disposing);
127 System.Text.Encoding.BigEndianUnicode
156 if (
string.IsNullOrEmpty(
value))
245 [Obsolete(
"This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.",
true)]
249 [Obsolete(
"This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.",
true)]
275 [Obsolete(
"This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.",
true)]
287 [Obsolete(
"WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId =
"SYSLIB0014", UrlFormat =
"https://aka.ms/dotnet-warnings/{0}")]
298 this.DownloadStringCompleted?.Invoke(
this, e);
303 this.DownloadDataCompleted?.Invoke(
this, e);
308 this.DownloadFileCompleted?.Invoke(
this, e);
313 this.DownloadProgressChanged?.Invoke(
this, e);
318 this.UploadStringCompleted?.Invoke(
this, e);
323 this.UploadDataCompleted?.Invoke(
this, e);
328 this.UploadFileCompleted?.Invoke(
this, e);
333 this.UploadValuesCompleted?.Invoke(
this, e);
338 this.UploadProgressChanged?.Invoke(
this, e);
343 this.OpenReadCompleted?.Invoke(
this, e);
348 this.OpenWriteCompleted?.Invoke(
this, e);
420 return asyncOperation;
446 webRequest.Proxy =
_proxy;
510 request = webRequest;
545 if (fileStream !=
null)
642 public byte[]
UploadData(
string address,
string? method,
byte[] data)
676 result =
UploadBits(webRequest,
null, data, 0,
null,
null);
687 request = webRequest;
695 string text = headers[
"Content-Type"];
698 text =
"application/octet-stream";
709 if (needsHeaderAndBoundary)
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";
719 formHeaderBytes =
Array.Empty<
byte>();
720 boundaryBytes =
Array.Empty<
byte>();
724 _contentLength = fs.Length + formHeaderBytes.Length + boundaryBytes.Length;
725 num = (int)
Math.
Min(8192
L, fs.Length);
730 headers[
"Content-Type"] =
text;
731 formHeaderBytes =
null;
732 boundaryBytes =
null;
736 num = (int)
Math.
Min(8192
L, fs.Length);
752 public byte[]
UploadFile(
string address,
string? method,
string fileName)
771 byte[] formHeaderBytes =
null;
772 byte[] boundaryBytes =
null;
775 OpenFileInternal(needsHeaderAndBoundary, fileName, out fs, out var
buffer, ref formHeaderBytes, ref boundaryBytes);
802 string text = headers[
"Content-Type"];
807 headers[
"Content-Type"] =
"application/x-www-form-urlencoded";
808 string value =
string.Empty;
810 string[] allKeys = data.
AllKeys;
811 foreach (
string text2
in allKeys)
813 stringBuilder.Append(
value);
815 stringBuilder.Append(
'=');
816 stringBuilder.Append(
UrlEncode(data[text2]));
854 return UploadBits(request,
null, valuesToUpload, 0,
null,
null);
881 public string UploadString(
string address,
string? method,
string data)
945 string text2 =
_headers[
"Connection"];
946 string text3 =
_headers[
"Content-Type"];
949 string text6 =
_headers[
"User-Agent"];
959 if (!
string.IsNullOrEmpty(
text))
961 httpWebRequest.Accept =
text;
963 if (!
string.IsNullOrEmpty(text2))
965 httpWebRequest.Connection = text2;
967 if (!
string.IsNullOrEmpty(text3))
969 httpWebRequest.ContentType = text3;
971 if (!
string.IsNullOrEmpty(text4))
973 httpWebRequest.Expect = text4;
975 if (!
string.IsNullOrEmpty(text5))
977 httpWebRequest.Referer = text5;
979 if (!
string.IsNullOrEmpty(text6))
981 httpWebRequest.UserAgent = text6;
983 if (!
string.IsNullOrEmpty(text7))
985 httpWebRequest.Host = text7;
1011 Uri result = address;
1019 string value =
string.Empty;
1040 byte[]
array =
new byte[(contentLength == -1 || contentLength > 65536) ? 65536 : contentLength];
1043 if (contentLength >
int.MaxValue)
1064 writeStream?.
Close();
1081 byte[] copyBuffer =
new byte[(contentLength == -1 || contentLength > 65536) ? 65536 : contentLength];
1084 if (contentLength >
int.MaxValue)
1088 writeStream.
SetLength(copyBuffer.Length);
1090 if (contentLength >= 0)
1092 _progress.TotalBytesToReceive = contentLength;
1097 if (readStream !=
null)
1101 int num = await readStream.
ReadAsync(
new Memory<byte>(copyBuffer)).ConfigureAwait(continueOnCapturedContext:
false);
1106 _progress.BytesReceived += num;
1126 writeStream?.
Close();
1132 completionDelegate(
null,
exception, asyncOp);
1143 header = (footer =
null);
1149 stream.Write(header, 0, header.Length);
1151 if (readStream !=
null)
1170 for (
int i = 0; i <
buffer.Length; i += num2)
1172 num2 = buffer.Length - i;
1173 if (chunkSize != 0 && num2 > chunkSize)
1182 stream.Write(footer, 0, footer.Length);
1200 _progress.HasUploadPhase =
true;
1207 footer = (
array =
null);
1215 _progress.BytesSent += header.Length;
1218 if (readStream !=
null)
1225 if (bytesRead2 <= 0)
1230 _progress.BytesSent += bytesRead2;
1238 while (bytesRead2 <
buffer.Length)
1240 int toWrite = buffer.Length - bytesRead2;
1241 if (chunkSize != 0 && toWrite > chunkSize)
1243 toWrite = chunkSize;
1246 bytesRead2 += toWrite;
1247 _progress.BytesSent += toWrite;
1254 _progress.BytesSent += footer.Length;
1269 completionDelegate(
null,
exception, asyncOp);
1276 if (
prefix ==
null || byteArray ==
null ||
prefix.Length > byteArray.Length)
1280 for (
int i = 0; i <
prefix.Length; i++)
1282 if (
prefix[i] != byteArray[i])
1308 string[] array2 =
array;
1309 foreach (
string text2
in array2)
1311 if (text2 ==
"charset")
1328 if (encoding ==
null)
1331 for (
int j = 0; j < array3.Length; j++)
1336 encoding = array3[j];
1337 num = preamble.Length;
1342 if (encoding ==
null)
1351 return encoding.
GetString(data, num, data.Length - num);
1364 [
return: NotNullIfNotNull(
"str")]
1379 for (
int i = 0; i <
count; i++)
1391 if (!alwaysCreateReturnValue && num == 0 && num2 == 0)
1397 for (
int j = 0; j <
count; j++)
1420 if ((
ch >=
'a' &&
ch <=
'z') || (
ch >=
'A' &&
ch <=
'Z') || (
ch >=
'0' &&
ch <=
'9'))
1529 string result =
null;
1532 if (returnBytes !=
null)
1615 fileStream?.
Close();
1646 string result =
null;
1647 if (error ==
null && bytesResult !=
null)
1693 if (this.UploadProgressChanged !=
null)
1695 chunkSize = (int)
Math.
Min(8192
L, data.Length);
1732 byte[] formHeaderBytes =
null;
1733 byte[] boundaryBytes =
null;
1737 OpenFileInternal(needsHeaderAndBoundary, fileName, out fs, out
buffer, ref formHeaderBytes, ref boundaryBytes);
1776 if (this.UploadProgressChanged !=
null)
1778 chunkSize = (int)
Math.
Min(8192
L, valuesToUpload.Length);
1821 webClient.DownloadStringCompleted -= completion;
1850 webClient.OpenReadCompleted -= completion;
1889 webClient.OpenWriteCompleted -= completion;
1928 webClient.UploadStringCompleted -= completion;
1957 webClient.DownloadDataCompleted -= completion;
1986 webClient.DownloadFileCompleted -= completion;
2025 webClient.UploadDataCompleted -= completion;
2064 webClient.UploadFileCompleted -= completion;
2103 webClient.UploadValuesCompleted -= completion;
2121 if (e.UserState != tcs)
2127 unregisterHandler(
this, handler);
2131 if (e.Error !=
null)
2133 tcs.TrySetException(e.Error);
2135 else if (e.Cancelled)
2137 tcs.TrySetCanceled();
2141 tcs.TrySetResult(getResult(e));
2154 if (this.UploadProgressChanged !=
null)
2156 int progressPercentage = (int)((progress.
TotalBytesToReceive >= 0 || progress.
BytesReceived != 0
L) ? ((progress.TotalBytesToSend < 0) ? 50 : ((progress.TotalBytesToReceive == 0
L) ? 100 : (50 * progress.BytesReceived / progress.TotalBytesToReceive + 50))) : ((progress.TotalBytesToSend >= 0) ? ((progress.
TotalBytesToSend == 0
L) ? 50 : (50 * progress.BytesSent / progress.
TotalBytesToSend)) : 0));
2160 else if (this.DownloadProgressChanged !=
null)
2167 [Obsolete(
"This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.",
true)]
static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression("argument")] string? paramName=null)
virtual ? string[] AllKeys
static AsyncOperation CreateOperation(object? userSuppliedState)
object? UserSuppliedState
void PostOperationCompleted(SendOrPostCallback d, object? arg)
void Post(SendOrPostCallback d, object? arg)
static void SuppressFinalize(object obj)
static char ToCharLower(int value)
static void Delete(string path)
static ? string GetFileName(string? path)
static string GetFullPath(string path)
void SetLength(long value)
Task WriteAsync(byte[] buffer, int offset, int count)
int Read(byte[] buffer, int offset, int count)
Task< int > ReadAsync(byte[] buffer, int offset, int count)
void Write(byte[] buffer, int offset, int count)
static byte Min(byte val1, byte val2)
static ICredentials DefaultCredentials
WebClientWriteStream(Stream stream, WebRequest request, WebClient webClient)
override void Dispose(bool disposing)
readonly WebRequest _request
readonly WebClient _webClient
WebHeaderCollection _headers
void OpenWriteAsync(Uri address, string? method, object? userToken)
byte[] UploadFile(Uri address, string? method, string fileName)
SendOrPostCallback _openWriteOperationCompleted
void UploadFileAsync(Uri address, string? method, string fileName, object? userToken)
string DownloadString(Uri address)
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
Stream OpenRead(string address)
static bool ByteArrayHasPrefix(byte[] prefix, byte[] byteArray)
UploadDataCompletedEventHandler? UploadDataCompleted
byte[] UploadBits(WebRequest request, Stream readStream, byte[] buffer, int chunkSize, byte[] header, byte[] footer)
Uri GetUri(string address)
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)
Stream OpenWrite(string address, string? method)
Stream OpenWrite(string address)
Task< Stream > OpenWriteTaskAsync(string address, string? method)
SendOrPostCallback _uploadValuesOperationCompleted
void UploadDataAsync(Uri address, string? method, byte[] data)
Task< byte[]> UploadFileTaskAsync(Uri address, string fileName)
SendOrPostCallback _reportUploadProgressChanged
Task< string > UploadStringTaskAsync(string address, string data)
byte[] UploadDataInternal(Uri address, string method, byte[] data, out WebRequest request)
Task< byte[]> UploadDataTaskAsync(Uri address, byte[] data)
Task< Stream > OpenReadTaskAsync(Uri address)
Stream OpenWrite(Uri address)
byte[] UploadFile(string address, string fileName)
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)
NameValueCollection QueryString
string UploadString(Uri address, string? method, string data)
bool AllowReadStreamBuffering
virtual void OnOpenReadCompleted(OpenReadCompletedEventArgs e)
void UploadValuesAsync(Uri address, string? method, NameValueCollection data, object? userToken)
Task< string > UploadStringTaskAsync(Uri address, string data)
byte[] DownloadDataInternal(Uri address, out WebRequest request)
AsyncCompletedEventHandler? DownloadFileCompleted
virtual WebRequest GetWebRequest(Uri address)
SendOrPostCallback _downloadFileOperationCompleted
void OpenReadAsync(Uri address)
void CopyHeadersTo(WebRequest request)
Task< string > UploadStringTaskAsync(Uri address, string? method, string data)
Task< byte[]> UploadValuesTaskAsync(string address, NameValueCollection data)
SendOrPostCallback _openReadOperationCompleted
ICredentials _credentials
Task< byte[]> UploadValuesTaskAsync(Uri address, string? method, NameValueCollection data)
byte[] UploadFile(Uri address, string fileName)
SendOrPostCallback _uploadFileOperationCompleted
static readonly char[] s_parseContentTypeSeparators
SendOrPostCallback _reportDownloadProgressChanged
void OpenFileInternal(bool needsHeaderAndBoundary, string fileName, out FileStream fs, out byte[] buffer, ref byte[] formHeaderBytes, ref byte[] boundaryBytes)
static readonly Encoding[] s_knownEncodings
virtual WebResponse GetWebResponse(WebRequest request, IAsyncResult result)
byte[] UploadValues(Uri address, string? method, NameValueCollection data)
SendOrPostCallback _uploadDataOperationCompleted
static Exception GetExceptionToPropagate(Exception e)
virtual WebResponse GetWebResponse(WebRequest request)
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)
byte[] UploadFile(string address, string? method, string fileName)
void DownloadStringAsyncCallback(byte[] returnBytes, Exception exception, object state)
void UploadStringAsync(Uri address, string data)
virtual void OnUploadStringCompleted(UploadStringCompletedEventArgs e)
virtual void OnOpenWriteCompleted(OpenWriteCompletedEventArgs e)
string GetStringUsingEncoding(WebRequest request, byte[] data)
static string UrlEncode(string str)
UploadValuesCompletedEventHandler? UploadValuesCompleted
RequestCachePolicy? CachePolicy
AsyncOperation StartAsyncOperation(object userToken)
void OpenWriteAsync(Uri address, string? method)
NameValueCollection _requestParameters
void UploadDataAsync(Uri address, byte[] data)
DownloadStringCompletedEventHandler? DownloadStringCompleted
Task< byte[]> UploadDataTaskAsync(Uri address, string? method, byte[] data)
byte[] DownloadData(string address)
Stream OpenWrite(Uri address, string? method)
string MapToDefaultMethod(Uri address)
Task< string > DownloadStringTaskAsync(Uri address)
SendOrPostCallback _downloadDataOperationCompleted
UploadProgressChangedEventHandler? UploadProgressChanged
string UploadString(string address, string? method, string data)
Task< string > UploadStringTaskAsync(string address, string? method, string data)
byte[] UploadValues(Uri address, NameValueCollection data)
void OpenReadAsync(Uri address, object? userToken)
WebHeaderCollection? ResponseHeaders
void DownloadStringAsync(Uri address, object? userToken)
DownloadDataCompletedEventHandler? DownloadDataCompleted
Task< byte[]> UploadValuesTaskAsync(string address, string? method, NameValueCollection data)
virtual void OnWriteStreamClosed(WriteStreamClosedEventArgs e)
SendOrPostCallback _uploadStringOperationCompleted
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)
byte[] UploadData(string address, string? method, byte[] data)
bool UseDefaultCredentials
static void AbortRequest(WebRequest request)
virtual void OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
void DownloadFile(Uri address, string fileName)
SendOrPostCallback _downloadStringOperationCompleted
string UploadString(Uri address, string data)
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
virtual void OnUploadValuesCompleted(UploadValuesCompletedEventArgs e)
WebHeaderCollection Headers
string UploadString(string address, string data)
void DownloadDataAsyncCallback(byte[] returnBytes, Exception exception, object state)
Task< Stream > OpenWriteTaskAsync(Uri address, string? method)
OpenWriteCompletedEventHandler? OpenWriteCompleted
void DownloadStringAsync(Uri address)
Task< Stream > OpenWriteTaskAsync(string address)
void DownloadFile(string address, string fileName)
Stream OpenRead(Uri address)
void UploadValuesAsync(Uri address, NameValueCollection data)
async Task< WebResponse > GetWebResponseTaskAsync(WebRequest request)
virtual void OnDownloadProgressChanged(DownloadProgressChangedEventArgs e)
virtual void OnDownloadFileCompleted(AsyncCompletedEventArgs e)
Task< byte[]> UploadDataTaskAsync(string address, byte[] data)
WriteStreamClosedEventHandler? WriteStreamClosed
void OpenWriteAsync(Uri address)
UploadFileCompletedEventHandler? UploadFileCompleted
void PostProgressChanged(AsyncOperation asyncOp, ProgressData progress)
string DownloadString(string address)
byte[] UploadValues(string address, NameValueCollection data)
virtual void OnUploadDataCompleted(UploadDataCompletedEventArgs e)
byte[] UploadValues(string address, string? method, NameValueCollection data)
DownloadProgressChangedEventHandler? DownloadProgressChanged
virtual void OnUploadProgressChanged(UploadProgressChangedEventArgs e)
Task< byte[]> UploadFileTaskAsync(string address, string fileName)
UploadStringCompletedEventHandler? UploadStringCompleted
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)
bool AllowWriteStreamBuffering
Task DownloadFileTaskAsync(Uri address, string fileName)
byte[] UploadData(string address, byte[] data)
byte[] UploadData(Uri address, byte[] data)
Task< byte[]> UploadDataTaskAsync(string address, string? method, byte[] data)
void UploadFileAsync(Uri address, string fileName)
byte[] DownloadData(Uri address)
static ? IWebProxy DefaultWebProxy
virtual IAsyncResult BeginGetResponse(AsyncCallback? callback, object? state)
static WebRequest Create(Uri requestUri, bool useUriBase)
virtual ? string ContentType
virtual WebResponse EndGetResponse(IAsyncResult asyncResult)
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
virtual WebHeaderCollection Headers
static string net_webclient
static string net_webclient_ContentType
static string net_webclient_Multipart
static string net_webclient_invalid_baseaddress
static string net_webstatus_MessageLengthLimitExceeded
static string net_webclient_no_concurrent_io_allowed
static Encoding GetEncoding(int codepage)
virtual byte[] GetBytes(char[] chars)
virtual byte[] GetPreamble()
unsafe string GetString(byte *bytes, int byteCount)
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)
static readonly AsyncCallback Callback
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
static bool Read(ref bool location)
static bool TryCreate([NotNullWhen(true)] string? uriString, UriKind uriKind, [NotNullWhen(true)] out Uri? result)
static readonly string UriSchemeFtp
static readonly string UriSchemeFile
override string ToString()
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)