22 [global::__DynamicallyInvokable]
25 private static class AbortState
27 public const int Public = 1;
29 public const int Internal = 2;
33 private enum Booleans : uint
40 IsVersionHttp10 = 0x80,
42 EnableDecompression = 0x200,
43 IsTunnelRequest = 0x400,
44 IsWebSocketRequest = 0x800,
48 private bool m_Saw100Continue;
50 private bool m_KeepAlive =
true;
52 private bool m_LockConnection;
54 private bool m_NtlmKeepAlive;
56 private bool m_PreAuthenticate;
60 private int m_Aborted;
62 private bool m_OnceFailed;
64 private bool m_Pipelined =
true;
66 private bool m_Retry =
true;
68 private bool m_HeadersCompleted;
70 private bool m_IsCurrentAuthenticationStateProxy;
72 private bool m_NeedsToReadForResponse =
true;
74 private bool m_BodyStarted;
76 private bool m_RequestSubmitted;
78 private bool m_OriginallyBuffered;
80 private bool m_Extra401Retry;
82 private long m_StartTimestamp;
88 private const int RequestLineConstantSize = 12;
90 private const string ContinueHeader =
"100-continue";
92 internal const string ChunkedHeader =
"chunked";
94 internal const string GZipHeader =
"gzip";
96 internal const string DeflateHeader =
"deflate";
98 internal const int DefaultReadWriteTimeout = 300000;
100 internal const int DefaultContinueTimeout = 350;
102 private static readonly
byte[] HttpBytes =
new byte[5]
111 private static readonly
WaitCallback s_EndWriteHeaders_Part2Callback = EndWriteHeaders_Part2Wrapper;
113 private static readonly TimerThread.Callback s_ContinueTimeoutCallback = ContinueTimeoutCallback;
115 private static readonly TimerThread.Queue s_ContinueTimerQueue = TimerThread.GetOrCreateQueue(350);
117 private static readonly TimerThread.Callback s_TimeoutCallback = TimeoutCallback;
119 private static readonly
WaitCallback s_AbortWrapper = AbortWrapper;
121 private static int s_UniqueGroupId;
123 private Booleans _Booleans = Booleans.Default;
125 private TimerThread.Timer m_ContinueTimer;
127 private InterlockedGate m_ContinueGate;
129 private int m_ContinueTimeout;
131 private TimerThread.Queue m_ContinueTimerQueue;
133 private object m_PendingReturnResult;
135 private LazyAsyncResult _WriteAResult;
137 private LazyAsyncResult _ReadAResult;
139 private LazyAsyncResult _ConnectionAResult;
141 private LazyAsyncResult _ConnectionReaderAResult;
143 private TriState _RequestIsAsync;
151 private object _CoreResponse;
153 private int _NestedWriteSideCheck;
155 private KnownHttpVerb _Verb;
157 private KnownHttpVerb _OriginVerb;
159 private bool _HostHasPort;
161 private Uri _HostUri;
165 private byte[] _WriteBuffer;
167 private int _WriteBufferLength;
169 private const int CachedWriteBufferSize = 512;
171 private static PinnableBufferCache _WriteBufferCache =
new PinnableBufferCache(
"System.Net.HttpWebRequest", 512);
173 private bool _WriteBufferFromPinnableCache;
175 private HttpWriteMode _HttpWriteMode;
179 private Uri _OriginUri;
181 private string _MediaType;
183 private long _ContentLength;
187 private ProxyChain _ProxyChain;
189 private string _ConnectionGroupName;
191 private bool m_InternalConnectionGroup;
193 private AuthenticationState _ProxyAuthenticationState;
195 private AuthenticationState _ServerAuthenticationState;
199 private HttpAbortDelegate _AbortDelegate;
201 private ConnectStream _SubmitWriteStream;
203 private ConnectStream _OldSubmitWriteStream;
205 private int _MaximumAllowedRedirections;
207 private int _AutoRedirects;
209 private bool _RedirectedToDifferentHost;
211 private int _RerequestCount;
213 private int _Timeout;
215 private TimerThread.Timer _Timer;
217 private TimerThread.Queue _TimerQueue;
219 private int _RequestContinueCount;
221 private int _ReadWriteTimeout;
225 private int _MaximumResponseHeadersLength;
227 private UnlockConnectionDelegate _UnlockDelegate;
229 private bool _returnResponseOnFailureStatusCode;
231 private Action<Stream> _resendRequestContent;
233 private long _originalContentLength;
237 [FriendAccessAllowed]
238 internal RtcState RtcState
244 internal TimerThread.Timer RequestTimer => _Timer;
246 internal bool Aborted => m_Aborted != 0;
255 return (_Booleans & Booleans.AllowAutoRedirect) != (Booleans)0u;
261 _Booleans |= Booleans.AllowAutoRedirect;
265 _Booleans &= ~Booleans.AllowAutoRedirect;
277 return (_Booleans & Booleans.AllowWriteStreamBuffering) != (Booleans)0u;
283 _Booleans |= Booleans.AllowWriteStreamBuffering;
287 _Booleans &= ~Booleans.AllowWriteStreamBuffering;
296 [global::__DynamicallyInvokable]
299 [global::__DynamicallyInvokable]
304 [global::__DynamicallyInvokable]
314 private bool ExpectContinue
318 return (_Booleans & Booleans.ExpectContinue) != (Booleans)0u;
324 _Booleans |= Booleans.ExpectContinue;
328 _Booleans &= ~Booleans.ExpectContinue;
336 [global::__DynamicallyInvokable]
339 [global::__DynamicallyInvokable]
342 if (_ReadAResult !=
null)
344 return _ReadAResult.InternalPeekCompleted;
350 internal bool NtlmKeepAlive
354 return m_NtlmKeepAlive;
358 m_NtlmKeepAlive = value;
362 internal bool NeedsToReadForResponse
366 return m_NeedsToReadForResponse;
370 m_NeedsToReadForResponse = value;
374 internal bool BodyStarted => m_BodyStarted;
391 internal bool LockConnection
395 return m_LockConnection;
399 m_LockConnection = value;
425 return m_PreAuthenticate;
429 m_PreAuthenticate = value;
433 private bool ProxySet
437 return (_Booleans & Booleans.ProxySet) != (Booleans)0u;
443 _Booleans |= Booleans.ProxySet;
447 _Booleans &= ~Booleans.ProxySet;
452 private bool RequestSubmitted => m_RequestSubmitted;
454 internal bool Saw100Continue
458 return m_Saw100Continue;
462 m_Saw100Continue = value;
473 return (_Booleans & Booleans.UnsafeAuthenticatedConnectionSharing) != (Booleans)0u;
477 ExceptionHelper.WebPermissionUnrestricted.Demand();
480 _Booleans |= Booleans.UnsafeAuthenticatedConnectionSharing;
484 _Booleans &= ~Booleans.UnsafeAuthenticatedConnectionSharing;
489 internal bool UnsafeOrProxyAuthenticatedConnectionSharing
493 if (!m_IsCurrentAuthenticationStateProxy)
501 private bool IsVersionHttp10
505 return (_Booleans & Booleans.IsVersionHttp10) != (Booleans)0u;
511 _Booleans |= Booleans.IsVersionHttp10;
515 _Booleans &= ~Booleans.IsVersionHttp10;
528 return (_Booleans & Booleans.SendChunked) != (Booleans)0u;
532 if (RequestSubmitted)
538 _Booleans |= Booleans.SendChunked;
542 _Booleans &= ~Booleans.SendChunked;
554 return m_AutomaticDecompression;
558 if (RequestSubmitted)
562 m_AutomaticDecompression = value;
566 internal HttpWriteMode HttpWriteMode
570 return _HttpWriteMode;
574 _HttpWriteMode = value;
593 ExceptionHelper.WebPermissionUnrestricted.Demand();
594 RequestCacheBinding binding = RequestCacheManager.GetBinding(
Uri.
UriSchemeHttp);
595 RequestCacheManager.SetBinding(
Uri.
UriSchemeHttp,
new RequestCacheBinding(binding.Cache, binding.Validator, value));
606 return SettingsSectionInternal.Section.MaximumResponseHeadersLength;
610 ExceptionHelper.WebPermissionUnrestricted.Demand();
611 if (value < 0 && value != -1)
615 SettingsSectionInternal.Section.MaximumResponseHeadersLength = value;
626 return SettingsSectionInternal.Section.MaximumErrorResponseLength;
630 ExceptionHelper.WebPermissionUnrestricted.Demand();
631 if (value < 0 && value != -1)
635 SettingsSectionInternal.Section.MaximumErrorResponseLength = value;
647 return _MaximumResponseHeadersLength;
651 if (RequestSubmitted)
655 if (value < 0 && value != -1)
659 _MaximumResponseHeadersLength = value;
663 internal HttpAbortDelegate AbortDelegate
667 _AbortDelegate = value;
671 internal LazyAsyncResult ConnectionAsyncResult => _ConnectionAResult;
673 internal LazyAsyncResult ConnectionReaderAsyncResult => _ConnectionReaderAResult;
675 internal bool UserRetrievedWriteStream
679 if (_WriteAResult !=
null)
681 return _WriteAResult.InternalPeekCompleted;
687 private bool IsOutstandingGetRequestStream
691 if (_WriteAResult !=
null)
693 return !_WriteAResult.InternalPeekCompleted;
703 return _RequestIsAsync != TriState.False;
707 if (_RequestIsAsync == TriState.Unspecified)
709 _RequestIsAsync = (value ? TriState.True : TriState.False);
714 internal UnlockConnectionDelegate UnlockConnectionDelegate
718 return _UnlockDelegate;
722 _UnlockDelegate = value;
726 private bool UsesProxy =>
ServicePoint.InternalProxyServicePoint;
730 internal bool UsesProxySemantics
736 if ((
object)_Uri.
Scheme == Uri.UriSchemeHttps || IsWebSocketRequest)
738 return IsTunnelRequest;
746 internal Uri ChallengedUri => CurrentAuthenticationState.ChallengedUri;
748 internal AuthenticationState ProxyAuthenticationState
752 if (_ProxyAuthenticationState ==
null)
754 _ProxyAuthenticationState =
new AuthenticationState(isProxyAuth:
true);
756 return _ProxyAuthenticationState;
760 internal AuthenticationState ServerAuthenticationState
764 if (_ServerAuthenticationState ==
null)
766 _ServerAuthenticationState =
new AuthenticationState(isProxyAuth:
false);
768 return _ServerAuthenticationState;
772 _ServerAuthenticationState = value;
776 internal AuthenticationState CurrentAuthenticationState
780 if (!m_IsCurrentAuthenticationStateProxy)
782 return _ServerAuthenticationState;
784 return _ProxyAuthenticationState;
788 m_IsCurrentAuthenticationStateProxy = (_ProxyAuthenticationState == value);
799 if (_ClientCertificates ==
null)
803 return _ClientCertificates;
811 _ClientCertificates = value;
817 [global::__DynamicallyInvokable]
820 [global::__DynamicallyInvokable]
823 return _CookieContainer;
825 [global::__DynamicallyInvokable]
828 _CookieContainer = value;
836 [global::__DynamicallyInvokable]
839 [global::__DynamicallyInvokable]
848 [global::__DynamicallyInvokable]
851 [global::__DynamicallyInvokable]
866 return _ContentLength;
870 if (RequestSubmitted)
878 _ContentLength = value;
879 _originalContentLength = value;
894 if (value < 0 && value != -1)
898 if (_Timeout != value)
906 private TimerThread.Queue TimerQueue
910 TimerThread.Queue queue = _TimerQueue;
913 queue = (_TimerQueue = TimerThread.GetOrCreateQueue((_Timeout == 0) ? 1 : _Timeout));
927 return _ReadWriteTimeout;
931 if (RequestSubmitted)
935 if (value <= 0 && value != -1)
939 _ReadWriteTimeout = value;
945 [global::__DynamicallyInvokable]
948 [global::__DynamicallyInvokable]
951 return m_ContinueTimeout;
953 [global::__DynamicallyInvokable]
956 if (RequestSubmitted)
960 if (value < 0 && value != -1)
964 if (m_ContinueTimeout != value)
966 m_ContinueTimeout = value;
969 m_ContinueTimerQueue = s_ContinueTimerQueue;
973 m_ContinueTimerQueue =
null;
979 private TimerThread.Queue ContinueTimerQueue
983 if (m_ContinueTimerQueue ==
null)
985 m_ContinueTimerQueue = TimerThread.GetOrCreateQueue((m_ContinueTimeout == 0) ? 1 : m_ContinueTimeout);
987 return m_ContinueTimerQueue;
991 internal bool HeadersCompleted
995 return m_HeadersCompleted;
999 m_HeadersCompleted = value;
1003 private bool CanGetRequestStream => !CurrentMethod.ContentBodyNotAllowed;
1005 internal bool CanGetResponseStream => !CurrentMethod.ExpectNoContentResponse;
1007 internal bool RequireBody => CurrentMethod.RequireContentBody;
1009 internal bool HasEntityBody
1013 if (HttpWriteMode != HttpWriteMode.Chunked && HttpWriteMode != HttpWriteMode.Buffer)
1015 if (HttpWriteMode == HttpWriteMode.ContentLength)
1035 return _ContinueDelegate;
1039 _ContinueDelegate = value;
1058 return GetHostAndPortString(_HostUri.
Host, _HostUri.
Port, _HostHasPort);
1064 if (RequestSubmitted)
1072 if (value.IndexOf(
'/') != -1 || !TryGetHostUri(value, out
Uri hostUri))
1076 CheckConnectPermission(hostUri, needExecutionContext:
false);
1080 _HostHasPort =
true;
1083 if (value.IndexOf(
':') == -1)
1085 _HostHasPort =
false;
1088 int num = value.IndexOf(
']');
1091 _HostHasPort =
true;
1095 _HostHasPort = (value.LastIndexOf(
':') > num);
1100 internal bool UseCustomHost
1104 if (_HostUri !=
null)
1106 return !_RedirectedToDifferentHost;
1119 return _MaximumAllowedRedirections;
1127 _MaximumAllowedRedirections = value;
1134 [global::__DynamicallyInvokable]
1135 public override string Method 1137 [global::__DynamicallyInvokable]
1140 return _OriginVerb.Name;
1142 [global::__DynamicallyInvokable]
1145 if (ValidationHelper.IsBlankString(value))
1149 if (ValidationHelper.IsInvalidHttpString(value))
1153 _OriginVerb = KnownHttpVerb.Parse(value);
1157 internal KnownHttpVerb CurrentMethod
1175 [global::__DynamicallyInvokable]
1178 [global::__DynamicallyInvokable]
1183 [global::__DynamicallyInvokable]
1194 [global::__DynamicallyInvokable]
1197 [global::__DynamicallyInvokable]
1206 [global::__DynamicallyInvokable]
1209 if (RequestSubmitted)
1217 internal bool IsTunnelRequest
1221 return (_Booleans & Booleans.IsTunnelRequest) != (Booleans)0u;
1227 _Booleans |= Booleans.IsTunnelRequest;
1231 _Booleans &= ~Booleans.IsTunnelRequest;
1236 internal bool IsWebSocketRequest
1240 return (_Booleans & Booleans.IsWebSocketRequest) != (Booleans)0u;
1246 _Booleans |= Booleans.IsWebSocketRequest;
1250 _Booleans &= ~Booleans.IsWebSocketRequest;
1261 return _ConnectionGroupName;
1265 if (!IsWebSocketRequest)
1267 _ConnectionGroupName = value;
1272 internal bool InternalConnectionGroup
1276 m_InternalConnectionGroup = value;
1283 [global::__DynamicallyInvokable]
1284 public override WebHeaderCollection
Headers 1286 [global::__DynamicallyInvokable]
1289 return _HttpRequestHeaders;
1291 [global::__DynamicallyInvokable]
1294 if (RequestSubmitted)
1299 string[] allKeys = value.AllKeys;
1300 foreach (
string name
in allKeys)
1302 webHeaderCollection.Add(name, value[name]);
1304 _HttpRequestHeaders = webHeaderCollection;
1318 ExceptionHelper.WebPermissionUnrestricted.Demand();
1323 ExceptionHelper.WebPermissionUnrestricted.Demand();
1324 if (RequestSubmitted)
1328 InternalProxy = value;
1342 if (_ProxyChain !=
null)
1344 _ProxyChain.Dispose();
1347 ServicePoint servicePoint = FindServicePoint(forceFind:
true);
1358 if (!IsVersionHttp10)
1368 IsVersionHttp10 =
false;
1373 IsVersionHttp10 =
true;
1382 [global::__DynamicallyInvokable]
1385 [global::__DynamicallyInvokable]
1388 return _HttpRequestHeaders[
"Content-Type"];
1390 [global::__DynamicallyInvokable]
1393 SetSpecialHeaders(
"Content-Type", value);
1421 return _HttpRequestHeaders[
"Transfer-Encoding"];
1425 if (ValidationHelper.IsBlankString(value))
1427 _HttpRequestHeaders.RemoveInternal(
"Transfer-Encoding");
1431 if (text.IndexOf(
"chunked") != -1)
1439 _HttpRequestHeaders.CheckUpdate(
"Transfer-Encoding", value);
1450 return _HttpRequestHeaders[
"Connection"];
1454 if (ValidationHelper.IsBlankString(value))
1456 _HttpRequestHeaders.RemoveInternal(
"Connection");
1460 bool flag = text.IndexOf(
"keep-alive") != -1;
1461 bool flag2 = text.IndexOf(
"close") != -1;
1466 _HttpRequestHeaders.CheckUpdate(
"Connection", value);
1472 [global::__DynamicallyInvokable]
1475 [global::__DynamicallyInvokable]
1478 return _HttpRequestHeaders[
"Accept"];
1480 [global::__DynamicallyInvokable]
1483 SetSpecialHeaders(
"Accept", value);
1493 return _HttpRequestHeaders[
"Referer"];
1497 SetSpecialHeaders(
"Referer", value);
1507 return _HttpRequestHeaders[
"User-Agent"];
1511 SetSpecialHeaders(
"User-Agent", value);
1523 return _HttpRequestHeaders[
"Expect"];
1527 if (ValidationHelper.IsBlankString(value))
1529 _HttpRequestHeaders.RemoveInternal(
"Expect");
1533 if (text.IndexOf(
"100-continue") != -1)
1537 _HttpRequestHeaders.CheckUpdate(
"Expect", value);
1547 return GetDateHeaderHelper(
"If-Modified-Since");
1551 SetDateHeaderHelper(
"If-Modified-Since", value);
1561 return GetDateHeaderHelper(
"Date");
1565 SetDateHeaderHelper(
"Date", value);
1569 internal byte[] WriteBuffer => _WriteBuffer;
1571 internal int WriteBufferLength => _WriteBufferLength;
1573 internal int RequestContinueCount => _RequestContinueCount;
1575 private bool IdentityRequired
1588 return credentialCache.IsDefaultInCache;
1600 internal ServerCertValidationCallback ServerCertValidationCallback
1612 if (ServerCertValidationCallback ==
null)
1616 return ServerCertValidationCallback.ValidationCallback;
1620 ExceptionHelper.InfrastructurePermission.Demand();
1623 ServerCertValidationCallback =
null;
1627 ServerCertValidationCallback =
new ServerCertValidationCallback(value);
1634 private bool SetRequestSubmitted()
1636 bool requestSubmitted = RequestSubmitted;
1637 m_RequestSubmitted =
true;
1638 return requestSubmitted;
1643 if (_HttpResponse ==
null)
1647 return _HttpResponse.
Headers[header];
1650 internal long SwitchToContentLength()
1656 if (HttpWriteMode == HttpWriteMode.Chunked)
1658 ConnectStream connectStream = _OldSubmitWriteStream;
1659 if (connectStream ==
null)
1661 connectStream = _SubmitWriteStream;
1663 if (connectStream.Connection !=
null && connectStream.Connection.IISVersion >= 6)
1669 long contentLength = _ContentLength;
1670 if (HttpWriteMode != HttpWriteMode.None)
1672 if (HttpWriteMode == HttpWriteMode.Buffer)
1674 _ContentLength = _SubmitWriteStream.BufferedData.Length;
1675 m_OriginallyBuffered =
true;
1676 HttpWriteMode = HttpWriteMode.ContentLength;
1679 if (NtlmKeepAlive && _OldSubmitWriteStream ==
null)
1681 _ContentLength = 0
L;
1682 _SubmitWriteStream.SuppressWrite =
true;
1683 if (!_SubmitWriteStream.BufferOnly)
1685 result = contentLength;
1687 if (HttpWriteMode == HttpWriteMode.Chunked)
1689 HttpWriteMode = HttpWriteMode.ContentLength;
1690 _SubmitWriteStream.SwitchToContentLength();
1692 _HttpRequestHeaders.RemoveInternal(
"Transfer-Encoding");
1695 if (_OldSubmitWriteStream !=
null)
1699 _ContentLength = 0
L;
1701 else if (_ContentLength == 0L || HttpWriteMode == HttpWriteMode.Chunked)
1703 if (_resendRequestContent ==
null)
1705 if (_OldSubmitWriteStream.BufferedData !=
null)
1707 _ContentLength = _OldSubmitWriteStream.BufferedData.Length;
1710 else if (HttpWriteMode == HttpWriteMode.Chunked)
1712 _ContentLength = -1
L;
1716 _ContentLength = _originalContentLength;
1719 if (HttpWriteMode == HttpWriteMode.Chunked && (_resendRequestContent ==
null || NtlmKeepAlive))
1721 HttpWriteMode = HttpWriteMode.ContentLength;
1722 _SubmitWriteStream.SwitchToContentLength();
1723 _HttpRequestHeaders.RemoveInternal(
"Transfer-Encoding");
1724 if (_resendRequestContent !=
null)
1734 private void PostSwitchToContentLength(
long value)
1738 _ContentLength = value;
1742 _ContentLength = -1
L;
1743 HttpWriteMode = HttpWriteMode.Chunked;
1747 private void ClearAuthenticatedConnectionResources()
1749 if (ProxyAuthenticationState.UniqueGroupId !=
null || ServerAuthenticationState.UniqueGroupId !=
null)
1751 ServicePoint.ReleaseConnectionGroup(GetConnectionGroupLine());
1753 UnlockConnectionDelegate unlockConnectionDelegate = UnlockConnectionDelegate;
1756 unlockConnectionDelegate?.Invoke();
1757 UnlockConnectionDelegate =
null;
1759 catch (Exception exception)
1761 if (NclUtilities.IsFatal(exception))
1766 ProxyAuthenticationState.ClearSession(
this);
1767 ServerAuthenticationState.ClearSession(
this);
1770 private void CheckProtocol(
bool onRequestStream)
1772 if (!CanGetRequestStream)
1774 if (onRequestStream)
1776 throw new ProtocolViolationException(SR.GetString(
"net_nouploadonget"));
1780 throw new ProtocolViolationException(SR.GetString(
"net_nocontentlengthonget"));
1782 HttpWriteMode = HttpWriteMode.None;
1784 else if (HttpWriteMode == HttpWriteMode.Unknown)
1790 HttpWriteMode = HttpWriteMode.Chunked;
1796 throw new ProtocolViolationException(SR.GetString(
"net_nochunkuploadonhttp10"));
1798 HttpWriteMode = HttpWriteMode.Buffer;
1803 HttpWriteMode = ((
ContentLength >= 0) ? HttpWriteMode.ContentLength : (onRequestStream ? HttpWriteMode.Buffer : HttpWriteMode.None));
1806 if (HttpWriteMode != HttpWriteMode.Chunked)
1810 throw new ProtocolViolationException(SR.GetString(
"net_contentlengthmissing"));
1814 throw new InvalidOperationException(SR.GetString(
"net_needchunked"));
1831 [global::__DynamicallyInvokable]
1832 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
1835 bool success =
false;
1840 Logging.Enter(Logging.Web,
this,
"BeginGetRequestStream",
"");
1842 CheckProtocol(onRequestStream:
true);
1843 ContextAwareResult contextAwareResult =
new ContextAwareResult(IdentityRequired, forceCaptureContext:
true,
this, state, callback);
1844 lock (contextAwareResult.StartPostingAsyncOp())
1846 if (_WriteAResult !=
null && _WriteAResult.InternalPeekCompleted)
1854 contextAwareResult.InvokeCallback(_WriteAResult.Result);
1858 Abort(exception, 1);
1864 if (!RequestSubmitted && NclUtilities.IsThreadPoolLow())
1872 if (_WriteAResult !=
null)
1876 if (SetRequestSubmitted())
1880 if (_ReadAResult !=
null)
1884 _WriteAResult = contextAwareResult;
1887 CurrentMethod = _OriginVerb;
1888 BeginSubmitRequest();
1890 contextAwareResult.FinishPostingAsyncOp();
1894 Logging.Exit(Logging.Web,
this,
"BeginGetRequestStream", contextAwareResult);
1897 return contextAwareResult;
1901 if (FrameworkEventSource.Log.IsEnabled())
1903 LogBeginGetRequestStream(success, synchronous:
false);
1919 [global::__DynamicallyInvokable]
1940 bool success =
false;
1945 Logging.Enter(Logging.Web,
this,
"EndGetRequestStream",
"");
1948 if (asyncResult ==
null)
1952 LazyAsyncResult lazyAsyncResult = asyncResult as LazyAsyncResult;
1953 if (lazyAsyncResult ==
null || lazyAsyncResult.AsyncObject !=
this)
1955 throw new ArgumentException(SR.GetString(
"net_io_invalidasyncresult"),
"asyncResult");
1957 if (lazyAsyncResult.EndCalled)
1961 ConnectStream connectStream = lazyAsyncResult.InternalWaitForCompletion() as ConnectStream;
1962 lazyAsyncResult.EndCalled =
true;
1963 if (connectStream ==
null)
1967 Logging.
Exception(Logging.Web,
this,
"EndGetRequestStream", lazyAsyncResult.Result as
Exception);
1969 throw (
Exception)lazyAsyncResult.Result;
1971 context =
new ConnectStreamContext(connectStream);
1974 Logging.Exit(Logging.Web,
this,
"EndGetRequestStream", connectStream);
1977 return connectStream;
1981 if (FrameworkEventSource.Log.IsEnabled())
1983 LogEndGetRequestStream(success, synchronous:
false);
2017 bool success =
false;
2020 if (FrameworkEventSource.Log.IsEnabled())
2022 LogBeginGetRequestStream(success:
true, synchronous:
true);
2026 Logging.Enter(Logging.Web,
this,
"GetRequestStream",
"");
2029 CheckProtocol(onRequestStream:
true);
2030 if (_WriteAResult ==
null || !_WriteAResult.InternalPeekCompleted)
2034 if (_WriteAResult !=
null)
2038 if (SetRequestSubmitted())
2042 if (_ReadAResult !=
null)
2046 _WriteAResult =
new LazyAsyncResult(
this,
null,
null);
2049 CurrentMethod = _OriginVerb;
2050 while (m_Retry && !_WriteAResult.InternalPeekCompleted)
2052 _OldSubmitWriteStream =
null;
2053 _SubmitWriteStream =
null;
2054 BeginSubmitRequest();
2056 while (Aborted && !_WriteAResult.InternalPeekCompleted)
2064 CheckWriteSideResponseProcessing();
2068 ConnectStream connectStream = _WriteAResult.InternalWaitForCompletion() as ConnectStream;
2069 _WriteAResult.EndCalled =
true;
2071 if (connectStream ==
null)
2075 Logging.Exception(Logging.Web,
this,
"EndGetRequestStream", _WriteAResult.Result as
Exception);
2079 context =
new ConnectStreamContext(connectStream);
2082 Logging.Exit(Logging.Web,
this,
"GetRequestStream", connectStream);
2084 return connectStream;
2088 if (FrameworkEventSource.Log.IsEnabled())
2090 LogEndGetRequestStream(success, synchronous:
true);
2095 internal void ErrorStatusCodeNotify(
Connection connection,
bool isKeepAlive,
bool fatal)
2097 ConnectStream submitWriteStream = _SubmitWriteStream;
2098 if (submitWriteStream !=
null && submitWriteStream.Connection == connection)
2102 submitWriteStream.ErrorResponseNotify(isKeepAlive);
2106 submitWriteStream.FatalResponseNotify();
2111 private HttpProcessingResult DoSubmitRequestProcessing(ref Exception exception)
2113 HttpProcessingResult httpProcessingResult = HttpProcessingResult.Continue;
2115 bool ntlmKeepAlive = NtlmKeepAlive;
2118 if (_HttpResponse !=
null)
2120 if (_CookieContainer !=
null)
2122 CookieModule.OnReceivedHeaders(
this);
2124 ProxyAuthenticationState.Update(
this);
2125 ServerAuthenticationState.Update(
this);
2129 bool disableUpload =
false;
2130 if (_HttpResponse ==
null)
2134 else if (CheckResubmitForCache(ref exception) || CheckResubmit(ref exception, ref disableUpload))
2139 else if (disableUpload)
2143 httpProcessingResult = HttpProcessingResult.WriteWait;
2145 OpenWriteSideResponseWindow();
2146 ConnectionReturnResult returnResult =
new ConnectionReturnResult(1);
2147 ConnectionReturnResult.Add(ref returnResult,
this, _HttpResponse.CoreResponseData);
2148 m_PendingReturnResult = returnResult;
2149 _HttpResponse =
null;
2150 _SubmitWriteStream.FinishedAfterWrite =
true;
2151 SetRequestContinue();
2156 WebException ex = exception as WebException;
2157 if (ex !=
null && ex.InternalStatus == WebExceptionInternalStatus.ServicePointFatal)
2159 ProxyChain proxyChain = _ProxyChain;
2160 if (proxyChain !=
null)
2162 servicePoint = ServicePointManager.FindServicePoint(proxyChain);
2164 flag = (servicePoint !=
null);
2169 return httpProcessingResult;
2171 if (base.CacheProtocol !=
null && _HttpResponse !=
null)
2173 base.CacheProtocol.Reset();
2175 ClearRequestForResubmit(ntlmKeepAlive);
2176 WebException ex2 = exception as WebException;
2179 m_Extra401Retry =
true;
2181 if (servicePoint ==
null)
2183 servicePoint = FindServicePoint(forceFind:
true);
2187 _ServicePoint = servicePoint;
2191 SubmitRequest(servicePoint);
2197 httpProcessingResult = HttpProcessingResult.WriteWait;
2198 return httpProcessingResult;
2202 if (httpProcessingResult == HttpProcessingResult.Continue)
2204 ClearAuthenticatedConnectionResources();
2220 [global::__DynamicallyInvokable]
2221 [HostProtection(
SecurityAction.LinkDemand, ExternalThreading =
true)]
2224 bool success =
false;
2229 Logging.Enter(Logging.Web,
this,
"BeginGetResponse",
"");
2231 if (!RequestSubmitted)
2233 CheckProtocol(onRequestStream:
false);
2235 ConnectStream connectStream = (_OldSubmitWriteStream !=
null) ? _OldSubmitWriteStream : _SubmitWriteStream;
2236 if (connectStream !=
null && !connectStream.IsClosed)
2238 if (connectStream.BytesLeftToWrite > 0)
2242 connectStream.Close();
2244 else if (connectStream ==
null && HasEntityBody)
2248 ContextAwareResult contextAwareResult =
new ContextAwareResult(IdentityRequired, forceCaptureContext:
true,
this, state, callback);
2249 if (!RequestSubmitted && NclUtilities.IsThreadPoolLow())
2255 lock (contextAwareResult.StartPostingAsyncOp())
2261 flag2 = SetRequestSubmitted();
2268 if (_ReadAResult !=
null)
2272 _ReadAResult = contextAwareResult;
2276 CheckDeferredCallDone(connectStream);
2281 Logging.Exit(Logging.Web,
this,
"BeginGetResponse", _ReadAResult.Result);
2290 contextAwareResult.InvokeCallback(_ReadAResult.Result);
2294 Abort(exception, 1);
2302 CurrentMethod = _OriginVerb;
2304 if (_RerequestCount > 0 || !flag2)
2308 BeginSubmitRequest();
2312 contextAwareResult.FinishPostingAsyncOp();
2316 Logging.Exit(Logging.Web,
this,
"BeginGetResponse", contextAwareResult);
2319 return contextAwareResult;
2323 if (FrameworkEventSource.Log.IsEnabled())
2325 LogBeginGetResponse(success, synchronous:
false);
2340 [global::__DynamicallyInvokable]
2343 bool success =
false;
2344 int statusCode = -1;
2349 Logging.Enter(Logging.Web,
this,
"EndGetResponse",
"");
2351 if (asyncResult ==
null)
2355 LazyAsyncResult lazyAsyncResult = asyncResult as LazyAsyncResult;
2356 if (lazyAsyncResult ==
null || lazyAsyncResult.AsyncObject !=
this)
2358 throw new ArgumentException(SR.GetString(
"net_io_invalidasyncresult"),
"asyncResult");
2360 if (lazyAsyncResult.EndCalled)
2365 lazyAsyncResult.EndCalled =
true;
2366 if (httpWebResponse ==
null)
2370 Logging.Exception(Logging.Web,
this,
"EndGetResponse", lazyAsyncResult.Result as
Exception);
2372 NetworkingPerfCounters.Instance.Increment(NetworkingPerfCounterName.HttpWebRequestFailed);
2373 throw (
Exception)lazyAsyncResult.Result;
2377 Logging.Exit(Logging.Web,
this,
"EndGetResponse", httpWebResponse);
2379 InitLifetimeTracking(httpWebResponse);
2380 statusCode = GetStatusCode(httpWebResponse);
2382 return httpWebResponse;
2387 statusCode = GetStatusCode(httpWebResponse2);
2392 if (FrameworkEventSource.Log.IsEnabled())
2394 LogEndGetResponse(success, synchronous:
false, statusCode);
2399 private void CheckDeferredCallDone(ConnectStream stream)
2402 if (obj == NclConstants.Sentinel)
2408 stream.ProcessWriteCallDone(obj as ConnectionReturnResult);
2424 bool success =
false;
2425 int statusCode = -1;
2428 if (FrameworkEventSource.Log.IsEnabled())
2430 LogBeginGetResponse(success:
true, synchronous:
true);
2434 Logging.Enter(Logging.Web,
this,
"GetResponse",
"");
2436 if (!RequestSubmitted)
2438 CheckProtocol(onRequestStream:
false);
2440 ConnectStream connectStream = (_OldSubmitWriteStream !=
null) ? _OldSubmitWriteStream : _SubmitWriteStream;
2441 if (connectStream !=
null && !connectStream.IsClosed)
2443 if (connectStream.BytesLeftToWrite > 0)
2447 connectStream.Close();
2449 else if (connectStream ==
null && HasEntityBody)
2458 flag2 = SetRequestSubmitted();
2466 if (_ReadAResult !=
null)
2473 ContextAwareResult contextAwareResult =
new ContextAwareResult(IdentityRequired, forceCaptureContext:
true,
this,
null,
null);
2474 contextAwareResult.StartPostingAsyncOp(lockCapture:
false);
2475 contextAwareResult.FinishPostingAsyncOp();
2476 _ReadAResult = contextAwareResult;
2480 _ReadAResult =
new LazyAsyncResult(
this,
null,
null);
2484 CheckDeferredCallDone(connectStream);
2489 _Timer = TimerQueue.CreateTimer(s_TimeoutCallback,
this);
2493 CurrentMethod = _OriginVerb;
2497 BeginSubmitRequest();
2499 while (!Async && Aborted && !_ReadAResult.InternalPeekCompleted)
2507 CheckWriteSideResponseProcessing();
2510 httpWebResponse = (_ReadAResult.InternalWaitForCompletion() as
HttpWebResponse);
2511 _ReadAResult.EndCalled =
true;
2513 if (httpWebResponse ==
null)
2517 Logging.Exception(Logging.Web,
this,
"GetResponse", _ReadAResult.Result as
Exception);
2519 NetworkingPerfCounters.Instance.Increment(NetworkingPerfCounterName.HttpWebRequestFailed);
2524 Logging.Exit(Logging.Web,
this,
"GetResponse", httpWebResponse);
2528 InitLifetimeTracking(httpWebResponse);
2530 statusCode = GetStatusCode(httpWebResponse);
2532 return httpWebResponse;
2537 statusCode = GetStatusCode(httpWebResponse2);
2542 if (FrameworkEventSource.Log.IsEnabled())
2544 LogEndGetResponse(success, synchronous:
true, statusCode);
2551 IRequestLifetimeTracker requestLifetimeTracker = httpWebResponse.ResponseStream as IRequestLifetimeTracker;
2552 requestLifetimeTracker.TrackRequestLifetime(m_StartTimestamp);
2555 internal void WriteCallDone(ConnectStream stream, ConnectionReturnResult returnResult)
2557 if (stream != ((_OldSubmitWriteStream !=
null) ? _OldSubmitWriteStream : _SubmitWriteStream))
2559 stream.ProcessWriteCallDone(returnResult);
2562 if (!UserRetrievedWriteStream)
2564 stream.ProcessWriteCallDone(returnResult);
2567 if (stream.FinishedAfterWrite)
2569 stream.ProcessWriteCallDone(returnResult);
2572 object value = (returnResult ==
null) ? ((
object)
Missing.
Value) : ((
object)returnResult);
2576 stream.ProcessWriteCallDone(returnResult);
2580 internal void NeedEndSubmitRequest()
2589 internal void CallContinueDelegateCallback(
object state)
2591 CoreResponseData coreResponseData = (CoreResponseData)state;
2592 ContinueDelegate((
int)coreResponseData.m_StatusCode, coreResponseData.m_ResponseHeaders);
2595 private DateTime GetDateHeaderHelper(
string headerName)
2597 string text = _HttpRequestHeaders[headerName];
2602 return HttpProtocolUtils.string2date(text);
2605 private void SetDateHeaderHelper(
string headerName, DateTime dateTime)
2609 SetSpecialHeaders(headerName,
null);
2613 SetSpecialHeaders(headerName, HttpProtocolUtils.date2string(dateTime));
2617 internal void FreeWriteBuffer()
2619 if (_WriteBufferFromPinnableCache)
2621 _WriteBufferCache.FreeBuffer(_WriteBuffer);
2622 _WriteBufferFromPinnableCache =
false;
2624 _WriteBufferLength = 0;
2625 _WriteBuffer =
null;
2628 private void SetWriteBuffer(
int bufferSize)
2630 if (bufferSize <= 512)
2632 if (!_WriteBufferFromPinnableCache)
2634 _WriteBuffer = _WriteBufferCache.AllocateBuffer();
2635 _WriteBufferFromPinnableCache =
true;
2641 _WriteBuffer =
new byte[bufferSize];
2643 _WriteBufferLength = bufferSize;
2646 private void SetSpecialHeaders(
string HeaderName,
string value)
2648 value = WebHeaderCollection.CheckBadChars(value, isHeaderValue:
true);
2649 _HttpRequestHeaders.RemoveInternal(HeaderName);
2650 if (value.Length != 0)
2652 _HttpRequestHeaders.AddInternal(HeaderName, value);
2657 [global::__DynamicallyInvokable]
2667 Logging.Enter(Logging.Web,
this,
"Abort", (exception ==
null) ?
"" : exception.
Message);
2671 NetworkingPerfCounters.Instance.Increment(NetworkingPerfCounterName.HttpWebRequestAborted);
2672 m_OnceFailed =
true;
2674 WebException ex = exception as WebException;
2675 if (exception ==
null)
2679 else if (ex ==
null)
2686 HttpAbortDelegate abortDelegate = _AbortDelegate;
2687 if (abortDelegate ==
null || abortDelegate(
this, ex))
2693 LazyAsyncResult lazyAsyncResult =
null;
2694 LazyAsyncResult lazyAsyncResult2 =
null;
2699 lazyAsyncResult = _WriteAResult;
2700 lazyAsyncResult2 = _ReadAResult;
2703 lazyAsyncResult?.InvokeCallback(ex);
2704 lazyAsyncResult2?.InvokeCallback(ex);
2708 LazyAsyncResult connectionAsyncResult = ConnectionAsyncResult;
2709 LazyAsyncResult connectionReaderAsyncResult = ConnectionReaderAsyncResult;
2710 connectionAsyncResult?.InvokeCallback(ex);
2711 connectionReaderAsyncResult?.InvokeCallback(ex);
2718 catch (InternalException)
2724 Logging.Exit(Logging.Web,
this,
"Abort",
"");
2728 private void CancelTimer()
2733 private static void TimeoutCallback(TimerThread.Timer timer,
int timeNoticed,
object context)
2738 private static void AbortWrapper(
object context)
2746 if ((servicePoint ==
null) | forceFind)
2750 if ((_ServicePoint ==
null) | forceFind)
2756 if (_ProxyChain !=
null)
2758 _ProxyChain.Dispose();
2760 _ServicePoint = ServicePointManager.FindServicePoint(_Uri, _Proxy, out _ProxyChain, ref _AbortDelegate, ref m_Aborted);
2763 Logging.Associate(Logging.Web,
this, _ServicePoint);
2767 servicePoint = _ServicePoint;
2769 return servicePoint;
2772 private void InvokeGetRequestStreamCallback()
2774 LazyAsyncResult writeAResult = _WriteAResult;
2775 if (writeAResult !=
null)
2779 writeAResult.InvokeCallback(_SubmitWriteStream);
2781 catch (Exception exception)
2783 if (NclUtilities.IsFatal(exception))
2787 Abort(exception, 1);
2793 internal void SetRequestSubmitDone(ConnectStream submitStream)
2797 ConnectionAsyncResult.InvokeCallback();
2801 submitStream.EnableWriteBuffering();
2803 if (submitStream.CanTimeout)
2810 Logging.Associate(Logging.Web,
this, submitStream);
2812 TransportContext transportContext =
new ConnectStreamContext(submitStream);
2813 ServerAuthenticationState.TransportContext = transportContext;
2814 ProxyAuthenticationState.TransportContext = transportContext;
2815 _SubmitWriteStream = submitStream;
2816 if (RtcState !=
null && RtcState.inputData !=
null && !RtcState.IsAborted)
2818 RtcState.outputData =
new byte[4];
2819 RtcState.result = _SubmitWriteStream.SetRtcOption(RtcState.inputData, RtcState.outputData);
2820 if (!RtcState.IsEnabled())
2824 RtcState.connectComplete.Set();
2826 if (Async && _CoreResponse !=
null && _CoreResponse !=
DBNull.Value)
2828 submitStream.CallDone();
2836 internal void WriteHeadersCallback(
WebExceptionStatus errorStatus, ConnectStream stream,
bool async)
2840 if (!EndWriteHeaders(async))
2844 else if (stream.BytesLeftToWrite == 0L)
2851 internal void SetRequestContinue()
2853 SetRequestContinue(
null);
2856 internal void SetRequestContinue(CoreResponseData continueResponse)
2858 _RequestContinueCount++;
2859 if (HttpWriteMode == HttpWriteMode.None || !m_ContinueGate.Complete())
2865 ExecutionContext executionContext = Async ? GetWritingContext().ContextCopy :
null;
2866 if (executionContext ==
null)
2868 ContinueDelegate((
int)continueResponse.m_StatusCode, continueResponse.m_ResponseHeaders);
2875 EndWriteHeaders_Part2();
2878 internal void OpenWriteSideResponseWindow()
2880 _CoreResponse =
DBNull.Value;
2881 _NestedWriteSideCheck = 0;
2884 internal void CheckWriteSideResponseProcessing()
2887 if (obj !=
DBNull.Value && obj !=
null && (Async || ++_NestedWriteSideCheck == 1))
2889 FinishContinueWait();
2890 Exception ex = obj as Exception;
2897 SetResponse(obj as CoreResponseData);
2902 internal void SetAndOrProcessResponse(
object responseOrException)
2904 if (responseOrException ==
null)
2906 throw new InternalException();
2908 CoreResponseData coreResponseData = responseOrException as CoreResponseData;
2909 WebException ex = responseOrException as WebException;
2913 if (obj.GetType() == typeof(CoreResponseData))
2915 if (coreResponseData !=
null)
2917 throw new InternalException();
2919 if (ex !=
null && ex.InternalStatus != WebExceptionInternalStatus.ServicePointFatal && ex.InternalStatus != 0)
2924 else if (obj.GetType() != typeof(DBNull))
2926 if (coreResponseData ==
null)
2928 throw new InternalException();
2930 ICloseEx closeEx = coreResponseData.m_ConnectStream as ICloseEx;
2931 if (closeEx !=
null)
2933 closeEx.CloseEx(CloseExState.Silent);
2937 coreResponseData.m_ConnectStream.Close();
2946 LazyAsyncResult connectionAsyncResult = ConnectionAsyncResult;
2947 LazyAsyncResult connectionReaderAsyncResult = ConnectionReaderAsyncResult;
2948 connectionAsyncResult.InvokeCallback(responseOrException);
2949 connectionReaderAsyncResult.InvokeCallback(responseOrException);
2953 if (coreResponseData !=
null)
2955 SetResponse(coreResponseData);
2966 Exception ex2 = responseOrException as Exception;
2972 throw new InternalException();
2975 if (obj !=
null && coreResponseData !=
null)
2977 ICloseEx closeEx2 = coreResponseData.m_ConnectStream as ICloseEx;
2978 if (closeEx2 !=
null)
2980 closeEx2.CloseEx(CloseExState.Silent);
2984 coreResponseData.m_ConnectStream.Close();
2990 throw new InternalException();
2992 FinishContinueWait();
2993 if (coreResponseData !=
null)
2995 SetResponse(coreResponseData);
2999 SetResponse(responseOrException as Exception);
3003 private void SetResponse(CoreResponseData coreResponseData)
3009 LazyAsyncResult connectionAsyncResult = ConnectionAsyncResult;
3010 LazyAsyncResult connectionReaderAsyncResult = ConnectionReaderAsyncResult;
3011 connectionAsyncResult.InvokeCallback(coreResponseData);
3012 connectionReaderAsyncResult.InvokeCallback(coreResponseData);
3014 if (coreResponseData !=
null)
3016 if (coreResponseData.m_ConnectStream.CanTimeout)
3024 Logging.Associate(Logging.Web,
this, coreResponseData.m_ConnectStream);
3028 Logging.Associate(Logging.Web,
this, _HttpResponse);
3037 catch (Exception exception)
3039 Abort(exception, 2);
3043 private void ProcessResponse()
3045 HttpProcessingResult httpProcessingResult = HttpProcessingResult.Continue;
3046 Exception exception =
null;
3047 if (DoSubmitRequestProcessing(ref exception) == HttpProcessingResult.Continue)
3051 if (_ReadAResult ==
null)
3055 if (_ReadAResult ==
null)
3057 _ReadAResult =
new LazyAsyncResult(
null,
null,
null);
3063 FinishRequest(_HttpResponse, exception);
3064 _ReadAResult.InvokeCallback(result);
3067 SetRequestContinue();
3073 catch (Exception exception2)
3075 Abort(exception2, 1);
3080 if (exception ==
null && _ReadAResult.Result != _HttpResponse)
3082 WebException ex = _ReadAResult.Result as WebException;
3083 if (ex !=
null && ex.Response !=
null)
3085 _HttpResponse.Abort();
3092 private void SetResponse(Exception E)
3094 HttpProcessingResult httpProcessingResult = HttpProcessingResult.Continue;
3095 WebException ex =
HaveResponse ? (_ReadAResult.Result as WebException) :
null;
3096 WebException ex2 =
E as WebException;
3097 if (ex !=
null && (ex.InternalStatus == WebExceptionInternalStatus.RequestFatal || ex.InternalStatus == WebExceptionInternalStatus.ServicePointFatal) && (ex2 ==
null || ex2.InternalStatus != 0))
3105 if (E !=
null && Logging.On)
3107 Logging.Exception(Logging.Web,
this,
"", ex);
3111 if (ex !=
null && (ex.InternalStatus == WebExceptionInternalStatus.Isolated || ex.InternalStatus == WebExceptionInternalStatus.ServicePointFatal || (ex.InternalStatus == WebExceptionInternalStatus.Recoverable && !m_OnceFailed)))
3113 if (ex.InternalStatus == WebExceptionInternalStatus.Recoverable)
3115 m_OnceFailed =
true;
3118 if (_SubmitWriteStream !=
null && _OldSubmitWriteStream ==
null && _SubmitWriteStream.BufferOnly)
3120 _OldSubmitWriteStream = _SubmitWriteStream;
3122 httpProcessingResult = DoSubmitRequestProcessing(ref E);
3125 catch (Exception ex3)
3127 if (NclUtilities.IsFatal(ex3))
3131 httpProcessingResult = HttpProcessingResult.Continue;
3136 if (httpProcessingResult == HttpProcessingResult.Continue)
3141 E = ((_HttpResponse !=
null) ?
new WebException(SR.GetString(
"net_servererror", NetRes.GetWebStatusCodeString(ResponseStatusCode, _HttpResponse.
StatusDescription)), E,
WebExceptionStatus.ProtocolError, _HttpResponse) :
new WebException(
E.Message, E));
3143 LazyAsyncResult lazyAsyncResult =
null;
3144 HttpWebResponse httpResponse = _HttpResponse;
3145 LazyAsyncResult writeAResult;
3148 writeAResult = _WriteAResult;
3149 if (_ReadAResult ==
null)
3151 _ReadAResult =
new LazyAsyncResult(
null,
null,
null, E);
3155 lazyAsyncResult = _ReadAResult;
3160 FinishRequest(httpResponse, E);
3163 writeAResult?.InvokeCallback(E);
3167 lazyAsyncResult?.InvokeCallback(E);
3172 (_ReadAResult.Result as HttpWebResponse)?.
Abort();
3173 if (base.CacheProtocol !=
null)
3175 base.CacheProtocol.Abort();
3182 internal override ContextAwareResult GetConnectingContext()
3188 ContextAwareResult contextAwareResult = ((HttpWriteMode == HttpWriteMode.None || _OldSubmitWriteStream !=
null || _WriteAResult ==
null || _WriteAResult.IsCompleted) ? _ReadAResult : _WriteAResult) as ContextAwareResult;
3189 if (contextAwareResult ==
null)
3191 throw new InternalException();
3193 return contextAwareResult;
3196 internal override ContextAwareResult GetWritingContext()
3202 ContextAwareResult contextAwareResult = _WriteAResult as ContextAwareResult;
3203 if (contextAwareResult ==
null || contextAwareResult.InternalPeekCompleted || HttpWriteMode == HttpWriteMode.None || HttpWriteMode == HttpWriteMode.Buffer || m_PendingReturnResult ==
DBNull.Value || m_OriginallyBuffered)
3205 contextAwareResult = (_ReadAResult as ContextAwareResult);
3207 if (contextAwareResult ==
null)
3209 throw new InternalException();
3211 return contextAwareResult;
3214 internal override ContextAwareResult GetReadingContext()
3220 ContextAwareResult contextAwareResult = _ReadAResult as ContextAwareResult;
3221 if (contextAwareResult ==
null)
3223 contextAwareResult = (_WriteAResult as ContextAwareResult);
3224 if (contextAwareResult ==
null)
3226 throw new InternalException();
3229 return contextAwareResult;
3232 private void BeginSubmitRequest()
3234 SubmitRequest(FindServicePoint(forceFind:
false));
3241 _ConnectionAResult =
new LazyAsyncResult(
this,
null,
null);
3242 _ConnectionReaderAResult =
new LazyAsyncResult(
this,
null,
null);
3243 OpenWriteSideResponseWindow();
3245 if (_Timer ==
null && !Async)
3247 _Timer = TimerQueue.CreateTimer(s_TimeoutCallback,
this);
3251 if (_SubmitWriteStream !=
null && _SubmitWriteStream.IsPostStream)
3255 _OldSubmitWriteStream = _SubmitWriteStream;
3257 _WriteBufferLength = 0;
3262 if (UsesProxySemantics && _Proxy !=
null && _Proxy.
Credentials !=
null)
3264 ProxyAuthenticationState.PreAuthIfNeeded(
this, _Proxy.
Credentials);
3268 ServerAuthenticationState.PreAuthIfNeeded(
this,
Credentials);
3271 if (WriteBufferLength == 0)
3275 if (!CheckCacheRetrieveBeforeSubmit())
3277 servicePoint.SubmitRequest(
this, GetConnectionGroupLine());
3284 CheckWriteSideResponseProcessing();
3289 private bool CheckCacheRetrieveBeforeSubmit()
3291 if (base.CacheProtocol ==
null)
3297 Uri uri = GetRemoteResourceUri();
3298 if (uri.Fragment.Length != 0)
3302 base.CacheProtocol.GetRetrieveStatus(uri,
this);
3303 if (base.CacheProtocol.ProtocolStatus == CacheValidationStatus.Fail)
3305 throw base.CacheProtocol.ProtocolException;
3307 if (base.CacheProtocol.ProtocolStatus != CacheValidationStatus.ReturnCachedResponse)
3311 if (HttpWriteMode != HttpWriteMode.None)
3313 throw new NotSupportedException(SR.GetString(
"net_cache_not_supported_body"));
3315 HttpRequestCacheValidator httpRequestCacheValidator = (HttpRequestCacheValidator)base.CacheProtocol.Validator;
3316 CoreResponseData coreResponseData =
new CoreResponseData();
3317 coreResponseData.m_IsVersionHttp11 = httpRequestCacheValidator.CacheHttpVersion.Equals(HttpVersion.Version11);
3318 coreResponseData.m_StatusCode = httpRequestCacheValidator.CacheStatusCode;
3319 coreResponseData.m_StatusDescription = httpRequestCacheValidator.CacheStatusDescription;
3320 coreResponseData.m_ResponseHeaders = httpRequestCacheValidator.CacheHeaders;
3321 coreResponseData.m_ContentLength = base.CacheProtocol.ResponseStreamLength;
3322 coreResponseData.m_ConnectStream = base.CacheProtocol.ResponseStream;
3324 _HttpResponse.InternalSetFromCache =
true;
3325 _HttpResponse.InternalSetIsCacheFresh = (httpRequestCacheValidator.CacheFreshnessStatus != CacheFreshnessStatus.Stale);
3329 catch (Exception exception)
3331 Abort(exception, 1);
3336 private bool CheckCacheRetrieveOnResponse()
3338 if (base.CacheProtocol ==
null)
3342 if (base.CacheProtocol.ProtocolStatus == CacheValidationStatus.Fail)
3344 throw base.CacheProtocol.ProtocolException;
3346 Stream responseStream = _HttpResponse.ResponseStream;
3347 base.CacheProtocol.GetRevalidateStatus(_HttpResponse, _HttpResponse.ResponseStream);
3348 if (base.CacheProtocol.ProtocolStatus == CacheValidationStatus.RetryResponseFromServer)
3352 if (base.CacheProtocol.ProtocolStatus != CacheValidationStatus.ReturnCachedResponse && base.CacheProtocol.ProtocolStatus != CacheValidationStatus.CombineCachedAndServerResponse)
3356 if (HttpWriteMode != HttpWriteMode.None)
3358 throw new NotSupportedException(SR.GetString(
"net_cache_not_supported_body"));
3360 CoreResponseData coreResponseData =
new CoreResponseData();
3361 HttpRequestCacheValidator httpRequestCacheValidator = (HttpRequestCacheValidator)base.CacheProtocol.Validator;
3362 coreResponseData.m_IsVersionHttp11 = httpRequestCacheValidator.CacheHttpVersion.Equals(HttpVersion.Version11);
3363 coreResponseData.m_StatusCode = httpRequestCacheValidator.CacheStatusCode;
3364 coreResponseData.m_StatusDescription = httpRequestCacheValidator.CacheStatusDescription;
3365 coreResponseData.m_ResponseHeaders = ((base.CacheProtocol.ProtocolStatus == CacheValidationStatus.CombineCachedAndServerResponse) ?
new WebHeaderCollection(httpRequestCacheValidator.CacheHeaders) : httpRequestCacheValidator.CacheHeaders);
3366 coreResponseData.m_ContentLength = base.CacheProtocol.ResponseStreamLength;
3367 coreResponseData.m_ConnectStream = base.CacheProtocol.ResponseStream;
3369 if (base.CacheProtocol.ProtocolStatus == CacheValidationStatus.ReturnCachedResponse)
3371 _HttpResponse.InternalSetFromCache =
true;
3372 _HttpResponse.InternalSetIsCacheFresh = base.CacheProtocol.IsCacheFresh;
3373 if (responseStream !=
null)
3377 responseStream.
Close();
3387 private void CheckCacheUpdateOnResponse()
3389 if (base.CacheProtocol !=
null)
3391 if (base.CacheProtocol.GetUpdateStatus(_HttpResponse, _HttpResponse.ResponseStream) == CacheValidationStatus.UpdateResponseInformation)
3393 _HttpResponse.ResponseStream = base.CacheProtocol.ResponseStream;
3395 else if (base.CacheProtocol.ProtocolStatus == CacheValidationStatus.Fail)
3397 throw base.CacheProtocol.ProtocolException;
3402 private void EndSubmitRequest()
3406 if (HttpWriteMode == HttpWriteMode.Buffer)
3408 InvokeGetRequestStreamCallback();
3412 if (WriteBufferLength == 0)
3414 long value = SwitchToContentLength();
3416 PostSwitchToContentLength(value);
3418 _SubmitWriteStream.WriteHeaders(Async);
3423 _SubmitWriteStream?.CallDone();
3430 CheckWriteSideResponseProcessing();
3435 internal bool EndWriteHeaders(
bool async)
3439 if (ShouldWaitFor100Continue())
3443 if (FinishContinueWait() && CompleteContinueGate())
3445 EndWriteHeaders_Part2();
3450 _SubmitWriteStream?.CallDone();
3456 internal bool ShouldWaitFor100Continue()
3458 if ((
ContentLength > 0 || HttpWriteMode == HttpWriteMode.Chunked) && ExpectContinue)
3460 return _ServicePoint.Understands100Continue;
3465 private static void ContinueTimeoutCallback(TimerThread.Timer timer,
int timeNoticed,
object context)
3468 if (httpWebRequest.HttpWriteMode != HttpWriteMode.None && httpWebRequest.FinishContinueWait() && httpWebRequest.CompleteContinueGate())
3474 internal void StartContinueWait()
3476 bool flag = m_ContinueGate.Trigger(exclusive:
true);
3479 internal void StartAsync100ContinueTimer()
3481 if (m_ContinueGate.StartTriggering(exclusive:
true))
3485 if (ShouldWaitFor100Continue())
3487 m_ContinueTimer = ContinueTimerQueue.CreateTimer(s_ContinueTimeoutCallback,
this);
3492 m_ContinueGate.FinishTriggering();
3497 internal bool FinishContinueWait()
3499 if (m_ContinueGate.StartSignaling(exclusive:
false))
3503 TimerThread.Timer continueTimer = m_ContinueTimer;
3504 m_ContinueTimer =
null;
3505 continueTimer?.Cancel();
3509 m_ContinueGate.FinishSignaling();
3516 private bool CompleteContinueGate()
3518 return m_ContinueGate.Complete();
3521 private static void EndWriteHeaders_Part2Wrapper(
object state)
3526 internal void EndWriteHeaders_Part2()
3530 ConnectStream submitWriteStream = _SubmitWriteStream;
3531 if (HttpWriteMode != HttpWriteMode.None)
3533 m_BodyStarted =
true;
3536 if (submitWriteStream.BufferOnly)
3538 _OldSubmitWriteStream = submitWriteStream;
3540 if (_OldSubmitWriteStream !=
null || (UserRetrievedWriteStream && _resendRequestContent !=
null))
3542 if (_resendRequestContent ==
null)
3544 submitWriteStream.ResubmitWrite(_OldSubmitWriteStream, NtlmKeepAlive &&
ContentLength == 0);
3546 else if (NtlmKeepAlive && (
ContentLength == 0L || HttpWriteMode == HttpWriteMode.Chunked))
3550 submitWriteStream.BytesLeftToWrite = 0
L;
3555 if (HttpWriteMode != HttpWriteMode.Chunked)
3557 submitWriteStream.BytesLeftToWrite = _originalContentLength;
3561 _resendRequestContent(submitWriteStream);
3563 catch (Exception exception)
3565 Abort(exception, 1);
3568 submitWriteStream.CloseInternal(internalCall:
true);
3574 if (submitWriteStream !=
null)
3576 submitWriteStream.CloseInternal(internalCall:
true);
3577 submitWriteStream =
null;
3579 _OldSubmitWriteStream =
null;
3581 InvokeGetRequestStreamCallback();
3585 _SubmitWriteStream?.CallDone();
3590 private int GenerateConnectRequestLine(
int headersSize)
3593 HostHeaderString hostHeaderString =
new HostHeaderString(GetSafeHostAndPort(addDefaultPort:
true, forcePunycode:
true));
3594 int writeBuffer = CurrentMethod.Name.Length + hostHeaderString.ByteCount + 12 + headersSize;
3595 SetWriteBuffer(writeBuffer);
3597 WriteBuffer[num++] = 32;
3598 hostHeaderString.Copy(WriteBuffer, num);
3599 num += hostHeaderString.ByteCount;
3600 WriteBuffer[num++] = 32;
3604 private string GetSafeHostAndPort(
bool addDefaultPort,
bool forcePunycode)
3606 if (IsTunnelRequest)
3608 return GetSafeHostAndPort(_OriginUri, addDefaultPort, forcePunycode);
3610 return GetSafeHostAndPort(_Uri, addDefaultPort, forcePunycode);
3613 private static string GetSafeHostAndPort(Uri sourceUri,
bool addDefaultPort,
bool forcePunycode)
3615 string hostName = (sourceUri.HostNameType !=
UriHostNameType.IPv6) ? (forcePunycode ? sourceUri.IdnHost : sourceUri.DnsSafeHost) : (
"[" + TrimScopeID(sourceUri.DnsSafeHost) +
"]");
3616 return GetHostAndPortString(hostName, sourceUri.Port, addDefaultPort || !sourceUri.IsDefaultPort);
3619 private static string GetHostAndPortString(
string hostName,
int port,
bool addPort)
3623 return hostName +
":" + port;
3628 private bool TryGetHostUri(
string hostName, out Uri hostUri)
3631 stringBuilder.
Append(
"://");
3632 stringBuilder.
Append(hostName);
3634 return Uri.TryCreate(stringBuilder.
ToString(),
UriKind.Absolute, out hostUri);
3637 private static string TrimScopeID(
string s)
3639 int num = s.LastIndexOf(
'%');
3642 return s.Substring(0, num);
3647 private int GenerateProxyRequestLine(
int headersSize)
3649 if ((
object)_Uri.
Scheme == Uri.UriSchemeFtp)
3651 return GenerateFtpProxyRequestLine(headersSize);
3655 HostHeaderString hostHeaderString =
new HostHeaderString(GetSafeHostAndPort(addDefaultPort:
false, forcePunycode:
true));
3657 int writeBuffer = CurrentMethod.Name.Length + components.Length + hostHeaderString.ByteCount + components2.Length + 12 + headersSize;
3658 SetWriteBuffer(writeBuffer);
3660 WriteBuffer[num++] = 32;
3662 hostHeaderString.Copy(WriteBuffer, num);
3663 num += hostHeaderString.ByteCount;
3665 WriteBuffer[num++] = 32;
3669 private int GenerateFtpProxyRequestLine(
int headersSize)
3674 HostHeaderString hostHeaderString =
new HostHeaderString(GetSafeHostAndPort(addDefaultPort:
false, forcePunycode:
true));
3678 string text2 =
null;
3679 string text3 =
null;
3681 if (credential !=
null && credential != FtpWebRequest.DefaultNetworkCredential)
3683 text2 = credential.InternalGetDomainUserName();
3684 text3 = credential.InternalGetPassword();
3685 text3 = ((text3 ==
null) ?
string.Empty : text3);
3689 text2 = text2.Replace(
":",
"%3A");
3690 text3 = text3.Replace(
":",
"%3A");
3691 text2 = text2.Replace(
"\\",
"%5C");
3692 text3 = text3.Replace(
"\\",
"%5C");
3693 text2 = text2.Replace(
"/",
"%2F");
3694 text3 = text3.Replace(
"/",
"%2F");
3695 text2 = text2.Replace(
"?",
"%3F");
3696 text3 = text3.Replace(
"?",
"%3F");
3697 text2 = text2.Replace(
"#",
"%23");
3698 text3 = text3.Replace(
"#",
"%23");
3699 text2 = text2.Replace(
"%",
"%25");
3700 text3 = text3.Replace(
"%",
"%25");
3701 text2 = text2.Replace(
"@",
"%40");
3702 text3 = text3.Replace(
"@",
"%40");
3703 text = text2 +
":" + text3 +
"@";
3706 int writeBuffer = CurrentMethod.Name.Length + components.Length + text.Length + hostHeaderString.ByteCount + components2.Length + 12 + headersSize;
3707 SetWriteBuffer(writeBuffer);
3709 WriteBuffer[num++] = 32;
3712 hostHeaderString.Copy(WriteBuffer, num);
3713 num += hostHeaderString.ByteCount;
3715 WriteBuffer[num++] = 32;
3719 private int GenerateRequestLine(
int headersSize)
3723 int writeBuffer = CurrentMethod.Name.Length + pathAndQuery.Length + 12 + headersSize;
3724 SetWriteBuffer(writeBuffer);
3726 WriteBuffer[num++] = 32;
3728 WriteBuffer[num++] = 32;
3732 internal Uri GetRemoteResourceUri()
3741 internal void UpdateHeaders()
3743 bool flag = IsTunnelRequest && _OriginUri.
Scheme == Uri.UriSchemeHttp;
3744 string s = (!UseCustomHost) ? GetSafeHostAndPort(flag, forcePunycode:
false) : GetSafeHostAndPort(_HostUri, _HostHasPort | flag, forcePunycode:
false);
3745 HostHeaderString hostHeaderString =
new HostHeaderString(s);
3746 string @
string = WebHeaderCollection.HeaderEncoding.GetString(hostHeaderString.Bytes, 0, hostHeaderString.ByteCount);
3747 _HttpRequestHeaders.ChangeInternal(
"Host", @
string);
3748 if (_CookieContainer !=
null)
3750 CookieModule.OnSendingHeaders(
this);
3754 internal void SerializeHeaders()
3756 if (HttpWriteMode != HttpWriteMode.None)
3758 if (HttpWriteMode == HttpWriteMode.Chunked)
3760 _HttpRequestHeaders.AddInternal(
"Transfer-Encoding",
"chunked");
3767 if ((
ContentLength > 0 || HttpWriteMode == HttpWriteMode.Chunked) && ExpectContinue)
3769 _HttpRequestHeaders.AddInternal(
"Expect",
"100-continue");
3772 string text = _HttpRequestHeaders.
Get(
"Accept-Encoding") ??
string.Empty;
3777 _HttpRequestHeaders.AddInternal(
"Accept-Encoding",
"gzip, deflate");
3781 _HttpRequestHeaders.AddInternal(
"Accept-Encoding",
"gzip");
3786 _HttpRequestHeaders.AddInternal(
"Accept-Encoding",
"deflate");
3788 string name =
"Connection";
3789 if (UsesProxySemantics || IsTunnelRequest)
3791 _HttpRequestHeaders.RemoveInternal(
"Connection");
3792 name =
"Proxy-Connection";
3793 if (!ValidationHelper.IsBlankString(
Connection))
3795 _HttpRequestHeaders.AddInternal(
"Proxy-Connection", _HttpRequestHeaders[
"Connection"]);
3800 _HttpRequestHeaders.RemoveInternal(
"Proxy-Connection");
3802 if (IsWebSocketRequest)
3804 string text2 = _HttpRequestHeaders.
Get(
"Connection") ??
string.Empty;
3807 _HttpRequestHeaders.AddInternal(
"Connection",
"Upgrade");
3812 if (IsVersionHttp10 || (
int)
ServicePoint.HttpBehaviour <= 1)
3814 _HttpRequestHeaders.AddInternal((UsesProxySemantics || IsTunnelRequest) ?
"Proxy-Connection" :
"Connection",
"Keep-Alive");
3817 else if (!IsVersionHttp10)
3819 _HttpRequestHeaders.AddInternal(name,
"Close");
3821 string text3 = _HttpRequestHeaders.
ToString();
3822 int byteCount = WebHeaderCollection.HeaderEncoding.GetByteCount(text3);
3823 int num = CurrentMethod.ConnectRequest ? GenerateConnectRequestLine(byteCount) : ((!UsesProxySemantics) ? GenerateRequestLine(byteCount) : GenerateProxyRequestLine(byteCount));
3824 Buffer.BlockCopy(HttpBytes, 0, WriteBuffer, num, HttpBytes.Length);
3825 num += HttpBytes.Length;
3826 WriteBuffer[num++] = 49;
3827 WriteBuffer[num++] = 46;
3828 WriteBuffer[num++] = (byte)(IsVersionHttp10 ? 48 : 49);
3829 WriteBuffer[num++] = 13;
3830 WriteBuffer[num++] = 10;
3835 WebHeaderCollection.HeaderEncoding.GetBytes(text3, 0, text3.Length, WriteBuffer, num);
3839 [Obsolete(
"This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.",
true)]
3849 Logging.Enter(Logging.Web,
this,
"HttpWebRequest", uri);
3851 CheckConnectPermission(uri, needExecutionContext:
false);
3852 m_StartTimestamp = NetworkingPerfCounters.GetTimestamp();
3853 NetworkingPerfCounters.Instance.Increment(NetworkingPerfCounterName.HttpWebRequestCreated);
3854 _HttpRequestHeaders =
new WebHeaderCollection(WebHeaderCollectionType.HttpWebRequest);
3856 _HttpWriteMode = HttpWriteMode.Unknown;
3857 _MaximumAllowedRedirections = 50;
3860 _ReadWriteTimeout = 300000;
3862 _ContentLength = -1
L;
3863 _originalContentLength = -1
L;
3864 _OriginVerb = KnownHttpVerb.Get;
3867 _ServicePoint = servicePoint;
3868 _RequestIsAsync = TriState.Unspecified;
3869 m_ContinueTimeout = 350;
3870 m_ContinueTimerQueue = s_ContinueTimerQueue;
3871 SetupCacheProtocol(_OriginUri);
3874 Logging.Exit(Logging.Web,
this,
"HttpWebRequest",
null);
3879 : this(proxyUri, null)
3881 _OriginVerb = KnownHttpVerb.Parse(
"CONNECT");
3883 _OriginUri = requestUri;
3884 IsTunnelRequest =
true;
3885 _ConnectionGroupName = ServicePointManager.SpecialConnectGroupName +
"(" + UniqueGroupId +
")";
3886 m_InternalConnectionGroup =
true;
3887 ServerAuthenticationState =
new AuthenticationState(isProxyAuth:
true);
3888 base.CacheProtocol =
null;
3889 m_ContinueTimeout = 350;
3890 m_ContinueTimerQueue = s_ContinueTimerQueue;
3893 internal HttpWebRequest(Uri uri,
bool returnResponseOnFailureStatusCode,
string connectionGroupName, Action<Stream> resendRequestContent)
3898 Logging.Enter(Logging.Web,
this,
"HttpWebRequest",
"uri: '" + uri +
"', connectionGroupName: '" + connectionGroupName +
"'");
3900 _returnResponseOnFailureStatusCode = returnResponseOnFailureStatusCode;
3901 _resendRequestContent = resendRequestContent;
3902 _Booleans &= ~Booleans.AllowWriteStreamBuffering;
3903 m_InternalConnectionGroup =
true;
3904 _ConnectionGroupName = connectionGroupName;
3907 Logging.Exit(Logging.Web,
this,
"HttpWebRequest",
null);
3912 : this(uri, servicePoint)
3914 IsWebSocketRequest = isWebSocketRequest;
3915 _ConnectionGroupName = connectionGroupName;
3921 [Obsolete(
"Serialization is obsoleted for this type. http://go.microsoft.com/fwlink/?linkid=14202")]
3924 : base(serializationInfo, streamingContext)
3926 ExceptionHelper.WebPermissionUnrestricted.Demand();
3929 Logging.Enter(Logging.Web,
this,
"HttpWebRequest", serializationInfo);
3936 if (!serializationInfo.
GetBoolean(
"_AllowWriteStreamBuffering"))
3938 _Booleans &= ~Booleans.AllowWriteStreamBuffering;
3940 HttpWriteMode = (HttpWriteMode)serializationInfo.
GetInt32(
"_HttpWriteMode");
3941 _MaximumAllowedRedirections = serializationInfo.
GetInt32(
"_MaximumAllowedRedirections");
3942 _AutoRedirects = serializationInfo.
GetInt32(
"_AutoRedirects");
3943 _Timeout = serializationInfo.
GetInt32(
"_Timeout");
3944 m_ContinueTimeout = 350;
3945 m_ContinueTimerQueue = s_ContinueTimerQueue;
3948 _ReadWriteTimeout = serializationInfo.
GetInt32(
"_ReadWriteTimeout");
3952 _ReadWriteTimeout = 300000;
3956 _MaximumResponseHeadersLength = serializationInfo.
GetInt32(
"_MaximumResponseHeadersLength");
3962 _ContentLength = serializationInfo.
GetInt64(
"_ContentLength");
3963 _MediaType = serializationInfo.
GetString(
"_MediaType");
3964 _OriginVerb = KnownHttpVerb.Parse(serializationInfo.
GetString(
"_OriginVerb"));
3965 _ConnectionGroupName = serializationInfo.
GetString(
"_ConnectionGroupName");
3967 _OriginUri = (
Uri)serializationInfo.
GetValue(
"_OriginUri", typeof(
Uri));
3968 SetupCacheProtocol(_OriginUri);
3971 Logging.Exit(Logging.Web,
this,
"HttpWebRequest",
null);
3981 GetObjectData(serializationInfo, streamingContext);
3996 serializationInfo.
AddValue(
"_HttpWriteMode", HttpWriteMode);
3997 serializationInfo.
AddValue(
"_MaximumAllowedRedirections", _MaximumAllowedRedirections);
3998 serializationInfo.
AddValue(
"_AutoRedirects", _AutoRedirects);
3999 serializationInfo.
AddValue(
"_Timeout", _Timeout);
4000 serializationInfo.
AddValue(
"_ReadWriteTimeout", _ReadWriteTimeout);
4001 serializationInfo.
AddValue(
"_MaximumResponseHeadersLength", _MaximumResponseHeadersLength);
4003 serializationInfo.
AddValue(
"_MediaType", _MediaType);
4004 serializationInfo.
AddValue(
"_OriginVerb", _OriginVerb);
4005 serializationInfo.
AddValue(
"_ConnectionGroupName", _ConnectionGroupName);
4007 serializationInfo.
AddValue(
"_OriginUri", _OriginUri, typeof(
Uri));
4008 base.GetObjectData(serializationInfo, streamingContext);
4011 internal static StringBuilder GenerateConnectionGroup(
string connectionGroupName,
bool unsafeConnectionGroup,
bool isInternalGroup)
4014 stringBuilder.
Append(unsafeConnectionGroup ?
"U>" :
"S>");
4015 if (isInternalGroup)
4017 stringBuilder.
Append(
"I>");
4019 return stringBuilder;
4022 internal string GetConnectionGroupLine()
4025 if (_Uri.
Scheme == Uri.UriSchemeHttps || IsTunnelRequest)
4029 stringBuilder.
Append(GetSafeHostAndPort(addDefaultPort:
true, forcePunycode:
false));
4030 stringBuilder.
Append(
"$");
4038 stringBuilder.
Append(
"&");
4042 if (ProxyAuthenticationState.UniqueGroupId !=
null)
4044 stringBuilder.
Append(ProxyAuthenticationState.UniqueGroupId);
4046 else if (ServerAuthenticationState.UniqueGroupId !=
null)
4048 stringBuilder.
Append(ServerAuthenticationState.UniqueGroupId);
4053 private static string GetDelegateId(RemoteCertificateValidationCallback callback)
4059 string name = callback.Method.Name;
4060 object target = callback.Target;
4062 return str +
"::" + name;
4070 private bool CheckResubmitForAuth()
4075 if (UsesProxySemantics && _Proxy !=
null && _Proxy.
Credentials !=
null)
4079 flag |= ProxyAuthenticationState.AttemptAuthenticate(
this, _Proxy.
Credentials);
4083 if (!m_Extra401Retry)
4095 flag |= ServerAuthenticationState.AttemptAuthenticate(
this,
Credentials);
4099 if (!m_Extra401Retry)
4107 if (!flag && flag2 && m_Extra401Retry)
4109 ClearAuthenticatedConnectionResources();
4110 m_Extra401Retry =
false;
4116 private bool CheckResubmitForCache(ref Exception e)
4118 if (!CheckCacheRetrieveOnResponse())
4124 Logging.PrintWarning(Logging.Web,
this,
"", SR.GetString(
"net_log_cache_validation_failed_resubmit"));
4130 Logging.PrintError(Logging.Web,
this,
"", SR.GetString(
"net_log_cache_refused_server_response"));
4132 e =
new InvalidOperationException(SR.GetString(
"net_cache_not_accept_response"));
4135 CheckCacheUpdateOnResponse();
4139 private void SetExceptionIfRequired(
string message, ref Exception e)
4141 SetExceptionIfRequired(message,
null, ref e);
4144 private void SetExceptionIfRequired(
string message, Exception innerException, ref Exception e)
4146 if (_returnResponseOnFailureStatusCode)
4150 if (innerException !=
null)
4152 Logging.Exception(Logging.Web,
this,
"", innerException);
4154 Logging.PrintWarning(Logging.Web,
this,
"", message);
4159 e =
new WebException(message, innerException,
WebExceptionStatus.ProtocolError, _HttpResponse);
4163 private bool CheckResubmit(ref Exception e, ref
bool disableUpload)
4170 if (!(flag = CheckResubmitForAuth()))
4172 SetExceptionIfRequired(SR.GetString(
"net_servererror", NetRes.GetWebStatusCodeString(ResponseStatusCode, _HttpResponse.
StatusDescription)), ref e);
4178 throw new WebException(SR.GetString(
"net_servererror", NetRes.GetWebStatusCodeString(ResponseStatusCode, _HttpResponse.
StatusDescription)), innerException,
WebExceptionStatus.ProtocolError, _HttpResponse);
4183 if (ServerAuthenticationState !=
null && ServerAuthenticationState.Authorization !=
null)
4185 HttpWebResponse httpResponse = _HttpResponse;
4186 if (httpResponse !=
null)
4188 httpResponse.InternalSetIsMutuallyAuthenticated = ServerAuthenticationState.Authorization.MutuallyAuthenticated;
4189 if (base.AuthenticationLevel ==
AuthenticationLevel.MutualAuthRequired && !httpResponse.IsMutuallyAuthenticated)
4191 throw new WebException(SR.GetString(
"net_webstatus_RequestCanceled"),
new ProtocolViolationException(SR.GetString(
"net_mutualauthfailed")),
WebExceptionStatus.RequestCanceled, httpResponse);
4197 ClearAuthenticatedConnectionResources();
4204 SetExceptionIfRequired(SR.GetString(
"net_servererror", NetRes.GetWebStatusCodeString(ResponseStatusCode, _HttpResponse.
StatusDescription)), ref e);
4209 SetExceptionIfRequired(SR.GetString(
"net_servererror", NetRes.GetWebStatusCodeString(ResponseStatusCode, _HttpResponse.
StatusDescription)), ref e);
4215 if (_AutoRedirects > _MaximumAllowedRedirections)
4217 SetExceptionIfRequired(SR.GetString(
"net_tooManyRedirections"), ref e);
4220 string location = _HttpResponse.
Headers.Location;
4221 if (location ==
null)
4223 SetExceptionIfRequired(SR.GetString(
"net_servererror", NetRes.GetWebStatusCodeString(ResponseStatusCode, _HttpResponse.
StatusDescription)), ref e);
4229 uri =
new Uri(_Uri, location);
4231 catch (UriFormatException innerException2)
4233 SetExceptionIfRequired(SR.GetString(
"net_resubmitprotofailed"), innerException2, ref e);
4236 if (IsWebSocketRequest)
4238 if (uri.Scheme == Uri.UriSchemeWs)
4240 UriBuilder uriBuilder =
new UriBuilder(uri);
4241 uriBuilder.Scheme = Uri.UriSchemeHttp;
4242 uri = uriBuilder.Uri;
4244 else if (uri.Scheme == Uri.UriSchemeWss)
4246 UriBuilder uriBuilder2 =
new UriBuilder(uri);
4247 uriBuilder2.Scheme = Uri.UriSchemeHttps;
4248 uri = uriBuilder2.Uri;
4251 if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps)
4253 SetExceptionIfRequired(SR.GetString(
"net_resubmitprotofailed"), ref e);
4256 if (!HasRedirectPermission(uri, ref e))
4265 string hostAndPortString = GetHostAndPortString(_HostUri.
Host, _HostUri.
Port, addPort:
true);
4267 bool flag2 = TryGetHostUri(hostAndPortString, out hostUri);
4268 if (!HasRedirectPermission(hostUri, ref e))
4277 Logging.PrintWarning(Logging.Web,
this,
"", SR.GetString(
"net_log_server_response_error_code", ((
int)ResponseStatusCode).ToString(
NumberFormatInfo.
InvariantInfo)));
4279 if (HttpWriteMode != HttpWriteMode.None)
4281 switch (ResponseStatusCode)
4285 if (CurrentMethod.Equals(KnownHttpVerb.Post))
4287 disableUpload =
true;
4291 disableUpload =
true;
4302 CurrentMethod = KnownHttpVerb.Get;
4303 ExpectContinue =
false;
4304 HttpWriteMode = HttpWriteMode.None;
4307 ICredentials credentials =
Credentials as CredentialCache;
4308 if (credentials ==
null)
4310 credentials = (
Credentials as SystemNetworkCredential);
4312 if (credentials ==
null)
4316 ProxyAuthenticationState.ClearAuthReq(
this);
4317 ServerAuthenticationState.ClearAuthReq(
this);
4318 if (_OriginUri.
Scheme == Uri.UriSchemeHttps)
4320 _HttpRequestHeaders.RemoveInternal(
"Referer");
4323 if (HttpWriteMode != HttpWriteMode.None && !
AllowWriteStreamBuffering && _resendRequestContent ==
null && UserRetrievedWriteStream && (HttpWriteMode != HttpWriteMode.ContentLength ||
ContentLength != 0L))
4325 e =
new WebException(SR.GetString(
"net_need_writebuffering"),
null,
WebExceptionStatus.ProtocolError, _HttpResponse);
4330 ClearAuthenticatedConnectionResources();
4334 Logging.PrintWarning(Logging.Web,
this,
"", SR.GetString(
"net_log_resubmitting_request"));
4339 private bool HasRedirectPermission(Uri uri, ref Exception resultException)
4343 CheckConnectPermission(uri, Async);
4347 resultException =
new SecurityException(SR.GetString(
"net_redirect_perm"),
new WebException(SR.GetString(
"net_resubmitcanceled"), innerException,
WebExceptionStatus.ProtocolError, _HttpResponse));
4353 private void CheckConnectPermission(Uri uri,
bool needExecutionContext)
4355 ExecutionContext executionContext = needExecutionContext ? GetReadingContext().ContextCopy :
null;
4357 if (executionContext ==
null)
4359 codeAccessPermission.
Demand();
4363 ExecutionContext.
Run(executionContext, NclUtilities.ContextRelativeDemandCallback, codeAccessPermission);
4367 private void ClearRequestForResubmit(
bool ntlmFollowupRequest)
4369 _HttpRequestHeaders.RemoveInternal(
"Host");
4370 _HttpRequestHeaders.RemoveInternal(
"Connection");
4371 _HttpRequestHeaders.RemoveInternal(
"Proxy-Connection");
4372 _HttpRequestHeaders.RemoveInternal(
"Content-Length");
4373 _HttpRequestHeaders.RemoveInternal(
"Transfer-Encoding");
4374 _HttpRequestHeaders.RemoveInternal(
"Expect");
4375 if (_HttpResponse !=
null && _HttpResponse.ResponseStream !=
null)
4377 if (!_HttpResponse.KeepAlive)
4379 (_HttpResponse.ResponseStream as ConnectStream)?.ErrorResponseNotify(isKeepAlive:
false);
4381 ICloseEx closeEx = _HttpResponse.ResponseStream as ICloseEx;
4382 if (closeEx !=
null)
4384 closeEx.CloseEx(CloseExState.Silent);
4388 _HttpResponse.ResponseStream.
Close();
4391 _AbortDelegate =
null;
4392 m_BodyStarted =
false;
4393 HeadersCompleted =
false;
4394 _WriteBufferLength = 0;
4395 m_Extra401Retry =
false;
4396 HttpWebResponse httpResponse = _HttpResponse;
4397 _HttpResponse =
null;
4398 m_ContinueGate.Reset();
4400 if (!Aborted && Async)
4402 _CoreResponse =
null;
4404 if (_SubmitWriteStream ==
null)
4408 if (((httpResponse !=
null && httpResponse.KeepAlive) || _SubmitWriteStream.IgnoreSocketErrors) && HasEntityBody)
4412 SetRequestContinue();
4414 if (ntlmFollowupRequest)
4416 NeedsToReadForResponse = !ShouldWaitFor100Continue();
4417 _SubmitWriteStream.CallDone();
4421 NeedsToReadForResponse = !ShouldWaitFor100Continue();
4422 _SubmitWriteStream.CloseInternal(internalCall:
true);
4424 else if (!Async && UserRetrievedWriteStream)
4426 _SubmitWriteStream.CallDone();
4429 if ((Async || UserRetrievedWriteStream) && _OldSubmitWriteStream !=
null && _OldSubmitWriteStream != _SubmitWriteStream)
4431 _SubmitWriteStream.CloseInternal(internalCall:
true);
4435 private void FinishRequest(HttpWebResponse response, Exception errorException)
4437 if (!_ReadAResult.InternalPeekCompleted && m_Aborted != 1 && response !=
null && errorException !=
null)
4439 response.ResponseStream = MakeMemoryStream(response.ResponseStream);
4441 if (errorException !=
null && _SubmitWriteStream !=
null && !_SubmitWriteStream.IsClosed)
4443 _SubmitWriteStream.ErrorResponseNotify(_SubmitWriteStream.Connection.KeepAlive);
4445 if (errorException ==
null && _HttpResponse !=
null && (_HttpWriteMode == HttpWriteMode.Chunked || _ContentLength > 0) && ExpectContinue && !Saw100Continue && _ServicePoint.Understands100Continue && !IsTunnelRequest && ResponseStatusCode <= (
HttpStatusCode)299)
4447 _ServicePoint.Understands100Continue =
false;
4453 if (stream ==
null || stream is SyncMemoryStream)
4457 SyncMemoryStream syncMemoryStream =
new SyncMemoryStream(0);
4462 byte[] array =
new byte[1024];
4465 while ((num = stream.
Read(array, 0, Math.Min(array.Length, num2))) > 0)
4467 syncMemoryStream.Write(array, 0, num);
4474 syncMemoryStream.Position = 0
L;
4475 return syncMemoryStream;
4479 return syncMemoryStream;
4485 ICloseEx closeEx = stream as ICloseEx;
4486 if (closeEx !=
null)
4488 closeEx.CloseEx(CloseExState.Silent);
4512 AddRange(
"bytes", (
long)from, (
long)to);
4561 public void AddRange(
string rangeSpecifier,
int from,
int to)
4563 AddRange(rangeSpecifier, (
long)from, (
long)to);
4578 public void AddRange(
string rangeSpecifier,
long from,
long to)
4580 if (rangeSpecifier ==
null)
4584 if (from < 0 || to < 0)
4612 AddRange(rangeSpecifier, (
long)range);
4623 public void AddRange(
string rangeSpecifier,
long range)
4625 if (rangeSpecifier ==
null)
4639 private bool AddRange(
string rangeSpecifier,
string from,
string to)
4641 string text = _HttpRequestHeaders[
"Range"];
4642 if (text ==
null || text.Length == 0)
4644 text = rangeSpecifier +
"=";
4648 if (
string.Compare(text.Substring(0, text.IndexOf(
'=')), rangeSpecifier,
StringComparison.OrdinalIgnoreCase) != 0)
4652 text =
string.Empty;
4657 text = text +
"-" + to;
4659 _HttpRequestHeaders.SetAddVerified(
"Range", text);
4663 private static int GetStatusCode(HttpWebResponse httpWebResponse)
4666 if (FrameworkEventSource.Log.IsEnabled() && httpWebResponse !=
null)
4670 result = (int)httpWebResponse.StatusCode;
4673 catch (ObjectDisposedException)
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,...
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
override Uri RequestUri
Gets the original Uniform Resource Identifier (URI) of the request.
The exception that is thrown when an error occurs while accessing the network through a pluggable pro...
int Port
Gets the port number of this URI.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
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...
static readonly Version Version11
Defines a T:System.Version instance for HTTP 1.1.
long GetInt64(string name)
Retrieves a 64-bit signed integer value from the T:System.Runtime.Serialization.SerializationInfo sto...
bool IsDefaultPort
Gets whether the port value of the URI is the default for this scheme.
override Stream EndGetRequestStream(IAsyncResult asyncResult)
Ends an asynchronous request for a T:System.IO.Stream object to use to write data.
UriHostNameType
Defines host name types for the M:System.Uri.CheckHostName(System.String) method.
HttpWebRequest()
Initializes a new instance of the T:System.Net.HttpWebRequest class.
DecompressionMethods
Represents the file compression and decompression encoding format to be used to compress the data rec...
override WebResponse EndGetResponse(IAsyncResult asyncResult)
Ends an asynchronous request to an Internet resource.
static readonly string UriSchemeHttp
Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP)....
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.
static void MemoryBarrier()
Synchronizes memory access as follows: The processor executing the current thread cannot reorder inst...
void AddRange(string rangeSpecifier, long range)
Adds a Range header to a request for a specific range from the beginning or end of the requested data...
bool SendChunked
Gets or sets a value that indicates whether to send data in segments to the Internet resource.
DateTime Date
Get or set the Date HTTP header value to use in an HTTP request.
Discovers the attributes of a method and provides access to method metadata.
virtual bool SupportsCookieContainer
Gets a value that indicates whether the request provides support for a T:System.Net....
abstract string FullName
Gets the fully qualified name of the type, including its namespace but not its assembly.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
NetworkAccess
Specifies network access permissions.
Defines a collection that stores T:System.Security.Cryptography.X509Certificates.X509Certificate obje...
bool KeepAlive
Gets or sets a value that indicates whether to make a persistent connection to the Internet resource.
EditorBrowsableState
Specifies the browsable state of a property or method from within an editor.
Represents a missing T:System.Object. This class cannot be inherited.
bool GetBoolean(string name)
Retrieves a Boolean value from the T:System.Runtime.Serialization.SerializationInfo store.
Makes a request to a Uniform Resource Identifier (URI). This is an abstract class.
RemoteCertificateValidationCallback ServerCertificateValidationCallback
Gets or sets a callback function to validate the server certificate.
void AddRange(long range)
Adds a byte range header to a request for a specific range from the beginning or end of the requested...
string Scheme
Gets the scheme name for this URI.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
void AddRange(long from, long to)
Adds a byte range header to the request for a specified range.
override string ContentType
Gets or sets the value of the Content-type HTTP header.
override Stream GetRequestStream()
Gets a T:System.IO.Stream object to use to write request data.
delegate void AsyncCallback(IAsyncResult ar)
References a method to be called when a corresponding asynchronous operation completes.
override string ConnectionGroupName
Gets or sets the name of the connection group for the request.
override bool PreAuthenticate
Gets or sets a value that indicates whether to send an Authorization header with the request.
Provides a container for a collection of T:System.Net.CookieCollection objects.
static bool UnsafeQueueUserWorkItem(WaitCallback callBack, object state)
Queues the specified delegate to the thread pool, but does not propagate the calling stack to the wor...
string PathAndQuery
Gets the P:System.Uri.AbsolutePath and P:System.Uri.Query properties separated by a question mark (?...
string Connection
Gets or sets the value of the Connection HTTP header.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
delegate bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication.
Defines the HTTP version numbers that are supported by the T:System.Net.HttpWebRequest and T:System....
HttpStatusCode
Contains the values of status codes defined for HTTP.
override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)
Begins an asynchronous request for a T:System.IO.Stream object to use to write data.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
static int DefaultMaximumResponseHeadersLength
Gets or sets the default for the P:System.Net.HttpWebRequest.MaximumResponseHeadersLength property.
void AddRange(int range)
Adds a byte range header to a request for a specific range from the beginning or end of the requested...
void AddRange(string rangeSpecifier, int range)
Adds a Range header to a request for a specific range from the beginning or end of the requested data...
A type representing a date and time value.
UriComponents
Specifies the parts of a T:System.Uri.
static int Exchange(ref int location1, int value)
Sets a 32-bit signed integer to a specified value and returns the original value, as an atomic operat...
static Encoding ASCII
Gets an encoding for the ASCII (7-bit) character set.
WebResponse Response
Gets the response that the remote host returned.
override WebResponse GetResponse()
Returns a response from an Internet resource.
HttpContinueDelegate ContinueDelegate
Gets or sets the delegate method called when an HTTP 100-continue response is received from the Inter...
override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
Begins an asynchronous request to an Internet resource.
int MaximumResponseHeadersLength
Gets or sets the maximum allowed length of the response headers.
override long ContentLength
Gets or sets the Content-length HTTP header.
abstract bool CanRead
When overridden in a derived class, gets a value indicating whether the current stream supports readi...
HttpWebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext)
Initializes a new instance of the T:System.Net.HttpWebRequest class from the specified instances of t...
int ReadWriteTimeout
Gets or sets a time-out in milliseconds when writing to or reading from a stream.
SecurityAction
Specifies the security actions that can be performed using declarative security.
string MediaType
Gets or sets the media type of the request.
virtual void Close()
Closes the current stream and releases any resources (such as sockets and file handles) associated wi...
DateTime IfModifiedSince
Gets or sets the value of the If-Modified-Since HTTP header.
Provides a response from a Uniform Resource Identifier (URI). This is an abstract class.
Represents the status of an asynchronous operation.
Manages the execution context for the current thread. This class cannot be inherited.
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
void AddValue(string name, object value, Type type)
Adds a value into the T:System.Runtime.Serialization.SerializationInfo store, where value is associa...
virtual bool AllowAutoRedirect
Gets or sets a value that indicates whether the request should follow redirection responses.
The T:System.Net.TransportContext class provides additional context about the underlying transport la...
bool Expect100Continue
Gets or sets a T:System.Boolean value that determines whether 100-Continue behavior is used.
Version ProtocolVersion
Gets or sets the version of HTTP to use for the request.
The exception that is thrown when an error is made while using a network protocol.
Throws an exception for a Win32 error code.
static readonly Version Version10
Defines a T:System.Version instance for HTTP 1.0.
DecompressionMethods AutomaticDecompression
Gets or sets the type of decompression that is used.
Provides storage for multiple credentials.
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.
static readonly DBNull Value
Represents the sole instance of the T:System.DBNull class.
override WebHeaderCollection Headers
Gets the headers that are associated with this response from the server.
virtual bool HaveResponse
Gets a value that indicates whether a response has been received from an Internet resource.
static int Increment(ref int location)
Increments a specified variable and stores the result, as an atomic operation.
static ICredentials DefaultCredentials
Gets the system credentials of the application.
A database null (column) value.
Defines the underlying structure of all code access permissions.
override IWebProxy Proxy
Gets or sets proxy information for the request.
Provides the base authentication interface for retrieving credentials for Web client authentication.
static RequestCachePolicy DefaultCachePolicy
Gets or sets the default cache policy for this request.
int MaximumAutomaticRedirections
Gets or sets the maximum number of redirects that the request follows.
static void Run(ExecutionContext executionContext, ContextCallback callback, object state)
Runs a method in a specified execution context on the current thread.
string Accept
Gets or sets the value of the Accept HTTP header.
Represents the version number of an assembly, operating system, or the common language runtime....
Type DeclaringType
Provides COM objects with version-independent access to the P:System.Reflection.MemberInfo....
WebRequest()
Initializes a new instance of the T:System.Net.WebRequest class.
static int DefaultMaximumErrorResponseLength
Gets or sets the default maximum length of an HTTP error response.
virtual HttpStatusCode StatusCode
Gets the status of the response.
Provides an HTTP-specific implementation of the T:System.Net.WebResponse class.
string GetComponents(UriComponents components, UriFormat format)
Gets the specified components of the current instance using the specified escaping for special charac...
void AddRange(string rangeSpecifier, long from, long to)
Adds a range header to a request for a specified range.
string Expect
Gets or sets the value of the Expect HTTP header.
ServicePoint ServicePoint
Gets the service point to use for the request.
virtual string Message
Gets a message that describes the current exception.
Defines an application's caching requirements for resources obtained by using T:System....
Contains constants that specify infinite time-out intervals. This class cannot be inherited.
virtual string StatusDescription
Gets the status description returned with the response.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
static void RevertAssert()
Causes any previous M:System.Security.CodeAccessPermission.Assert for the current frame to be removed...
Stream GetRequestStream(out TransportContext context)
Gets a T:System.IO.Stream object to use to write request data and outputs the T:System....
int ContinueTimeout
Gets or sets a timeout, in milliseconds, to wait until the 100-Continue is received from the server.
WebExceptionStatus
Defines status codes for the T:System.Net.WebException class.
Exception()
Initializes a new instance of the T:System.Exception class.
NetworkCredential GetCredential(Uri uri, string authType)
Returns a T:System.Net.NetworkCredential object that is associated with the specified URI,...
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
Stream EndGetRequestStream(IAsyncResult asyncResult, out TransportContext context)
Ends an asynchronous request for a T:System.IO.Stream object to use to write data and outputs the T:S...
int Count
Gets the number of elements contained in the T:System.Collections.CollectionBase instance....
static readonly Missing Value
Represents the sole instance of the T:System.Reflection.Missing class.
virtual bool AllowReadStreamBuffering
Gets or sets a value that indicates whether to buffer the received from the Internet resource.
override bool? UseDefaultCredentials
Gets or sets a T:System.Boolean value that controls whether default credentials are sent with request...
UriFormat
Controls how URI information is escaped.
Allows an object to control its own serialization and deserialization.
Uri Address
Gets the Uniform Resource Identifier (URI) of the Internet resource that actually responds to the req...
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
string Host
Get or set the Host header value to use in an HTTP request independent from the request URI.
virtual bool AllowWriteStreamBuffering
Gets or sets a value that indicates whether to buffer the data sent to the Internet resource.
void AddRange(string rangeSpecifier, int from, int to)
Adds a range header to a request for a specified range.
bool UnsafeAuthenticatedConnectionSharing
Gets or sets a value that indicates whether to allow high-speed NTLM-authenticated connection sharing...
override int GetHashCode()
Builds a hash value based on all values contained in the current T:System.Security....
string GetString(string name)
Retrieves a T:System.String value from the T:System.Runtime.Serialization.SerializationInfo store.
bool CloseConnectionGroup(string connectionGroupName)
Removes the specified connection group from this T:System.Net.ServicePoint object.
object GetValue(string name, Type type)
Retrieves a value from the T:System.Runtime.Serialization.SerializationInfo store.
override ICredentials Credentials
Gets or sets authentication information for the request.
bool Pipelined
Gets or sets a value that indicates whether to pipeline the request to the Internet resource.
Specifies that the class can be serialized.
void AddRange(int from, int to)
Adds a byte range header to the request for a specified range.
string TransferEncoding
Gets or sets the value of the Transfer-encoding HTTP header.
ICredentials Credentials
The credentials to submit to the proxy server for authentication.
The exception that is thrown when a method call is invalid for the object's current state.
override WebHeaderCollection Headers
Specifies a collection of the name/value pairs that make up the HTTP headers.
int GetInt32(string name)
Retrieves a 32-bit signed integer value from the T:System.Runtime.Serialization.SerializationInfo sto...
override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data required to serialize the ...
Provides the base interface for implementation of proxy access for the T:System.Net....
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
Provides credentials for password-based authentication schemes such as basic, digest,...
delegate void WaitCallback(object state)
Represents a callback method to be executed by a thread pool thread.
Provides information about a specific culture (called a locale for unmanaged code development)....
override string Method
Gets or sets the method for the request.
SecurityPermissionFlag
Specifies access flags for the security permission object.
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
Provides an HTTP-specific implementation of the T:System.Net.WebRequest class.
override void Abort()
Cancels a request to an Internet resource.
Controls access to non-public types and members through the N:System.Reflection APIs....
static new RequestCachePolicy DefaultCachePolicy
Gets or sets the default cache policy for this request.
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
string Host
Gets the host component of this instance.
Provides atomic operations for variables that are shared by multiple threads.
X509CertificateCollection ClientCertificates
Gets or sets the collection of security certificates that are associated with this request.
The default setting for this enumeration, which is currently F:System.GCCollectionMode....
The exception that is thrown when a security error is detected.
string Referer
Gets or sets the value of the Referer HTTP header.
HttpResponseHeader
The HTTP headers that can be specified in a server response.
Provides connection management for HTTP connections.
delegate void HttpContinueDelegate(int StatusCode, WebHeaderCollection httpHeaders)
Represents the method that notifies callers when a continue response is received by the client.
Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I...
Represents a nonexistent value. This class cannot be inherited.
AuthenticationLevel
Specifies client requirements for authentication and impersonation when using the T:System....
static void SpinWait(int iterations)
Causes a thread to wait the number of times defined by the iterations parameter.
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....
string UserAgent
Gets or sets the value of the User-agent HTTP header.
Creates and controls a thread, sets its priority, and gets its status.