HttpWebRequest internal retries in .NET Framework 4.8 — can a single HTTP transmission be guaranteed?

Cinthia Franco 0 Reputation points
2026-11-18T13:21:55.1+00:00

Hello,

I am investigating the HTTP request behavior of System.Net.HttpWebRequest in a Windows PowerShell 5.1 environment.

Environment

  • Windows PowerShell: 5.1

CLR version: 4.0.30319.42000

.NET Framework: 4.8 (local runtime inventory reports version 4.8.10008.0)

HTTP API: System.Net.HttpWebRequest

Technical background

My application performs a read-only HTTP GET request.

The implementation uses:

One application-level call to GetResponse().

Automatic redirects disabled.

No application-level retry loop.

Explicit Bearer authorization.

Finite connection and read timeouts.

A persistent local guard to prevent accidental repeated execution.

My main concern

While reviewing the Microsoft Reference Source implementation of HttpWebRequest.cs, I found internal retry-related state, including the m_Retry field.

However, I could not establish whether that source revision exactly matches the System.dll binary installed on my machine.

Questions

Can HttpWebRequest internally retransmit an HTTP GET request after a connection failure or another transient network error?

Can one application-level GetResponse() invocation result in multiple HTTP transmissions?

Under what conditions can the .NET Framework internally retry or resend a request?

Is there a documented public property or supported configuration that disables all internal retransmissions?

Do AllowAutoRedirect=false, KeepAlive=false, PreAuthenticate=false and Credentials=null prevent any form of internal retry?

Is there a Microsoft-supported way to guarantee at most one HTTP transmission for a specific HttpWebRequest instance?

If this guarantee is not available, what approach does Microsoft recommend for applications that must avoid duplicate HTTP requests?

I understand that one GetResponse() invocation does not necessarily prove that only one HTTP request was transmitted over the network.

I would appreciate any documentation, source-code references or technical guidance applicable specifically to .NET Framework 4.8 and Windows PowerShell 5.1.

Thank you for your help.Hello,

I am investigating the HTTP request behavior of System.Net.HttpWebRequest in a Windows PowerShell 5.1 environment.

Environment

Windows PowerShell: 5.1

CLR version: 4.0.30319.42000

.NET Framework: 4.8 (local runtime inventory reports version 4.8.10008.0)

HTTP API: System.Net.HttpWebRequest

Technical background

My application performs a read-only HTTP GET request.

The implementation uses:

One application-level call to GetResponse().

Automatic redirects disabled.

No application-level retry loop.

Explicit Bearer authorization.

Finite connection and read timeouts.

A persistent local guard to prevent accidental repeated execution.

My main concern

While reviewing the Microsoft Reference Source implementation of HttpWebRequest.cs, I found internal retry-related state, including the m_Retry field.

However, I could not establish whether that source revision exactly matches the System.dll binary installed on my machine.

Questions

Can HttpWebRequest internally retransmit an HTTP GET request after a connection failure or another transient network error?

Can one application-level GetResponse() invocation result in multiple HTTP transmissions?

Under what conditions can the .NET Framework internally retry or resend a request?

Is there a documented public property or supported configuration that disables all internal retransmissions?

Do AllowAutoRedirect=false, KeepAlive=false, PreAuthenticate=false and Credentials=null prevent any form of internal retry?

Is there a Microsoft-supported way to guarantee at most one HTTP transmission for a specific HttpWebRequest instance?

If this guarantee is not available, what approach does Microsoft recommend for applications that must avoid duplicate HTTP requests?

I understand that one GetResponse() invocation does not necessarily prove that only one HTTP request was transmitted over the network.

I would appreciate any documentation, source-code references or technical guidance applicable specifically to .NET Framework 4.8 and Windows PowerShell 5.1.

Thank you for your help.

Developer technologies | .NET | .NET Runtime
0 comments No comments

3 answers

Sort by: Oldest
  1. AI answer

    2026-11-18T13:23:20.5466667+00:00

    HttpWebRequest in .NET Framework cannot provide a Microsoft-supported guarantee of at most one HTTP transmission per GetResponse() call; design the operation as idempotent or add server-side deduplication when duplicates must have no additional effect.

    What can happen in .NET Framework 4.8

    One synchronous call to GetResponse() can result in more than one network transmission.

    The published .NET Framework Reference Source contains an internal resubmission path for:

    • WebExceptionStatus.KeepAliveFailure
    • WebExceptionStatus.PipelineFailure

    On the synchronous path, the implementation sets m_Retry = true, allowing GetResponse() processing to submit the request again. The asynchronous path can call the submission routine again directly. Therefore, a connection that fails while being reused—or a pipeline failure—can cause a transparent resend inside the same application-level operation ^1^.

    This establishes that retransmission logic exists, but it does not establish that every transient network error is retried. The available public documentation does not provide an exhaustive, version-pinned table of all retry branches in the particular System.dll build installed on your computer.

    Also, m_Retry is implementation state, not a public contract. Microsoft explicitly warns that internal HttpWebRequest fields are unsupported for production use; for example, _AutoRedirects is documented as internal and unsupported ^2^. Reflection against m_Retry, patching it, or relying on its initial value would therefore not be a supported control.

    Effect of the properties you listed

    These settings suppress particular protocol behaviors, but not every possible resubmission path:

    • AllowAutoRedirect = false prevents automatic following of HTTP 3xx responses. The 3xx response is returned to the application instead ^3^. It does not represent a general retry switch.
    • KeepAlive = false requests a nonpersistent connection rather than a persistent one ^4^. This should avoid the ordinary stale reused-connection scenario associated with KeepAliveFailure, but the documentation does not define it as disabling every internal retransmission.
    • PreAuthenticate = false controls whether authentication information is sent preemptively after prior authentication. It is not a retry control ^5^.
    • Credentials = null with an explicit Bearer [Token] avoids credential-based authentication modules for the request. It does not create an at-most-once transport guarantee.
    • Timeouts bound waiting time. GetResponse() can throw WebException on timeout or another processing error, but an exception cannot establish that no bytes reached the server ^6^.

    Consequently, your combination of settings reduces redirect, connection-reuse, and challenge-authentication traffic, but it does not form a documented “single transmission” mode.

    Why transport-level at-most-once is not enough

    A client can transmit a complete request and then lose the response because the connection resets or times out. From the client’s perspective, that state is ambiguous: the server might not have received the request, or it might have received and processed it successfully.

    Microsoft’s retry guidance describes this exact boundary: a service can process a request successfully but fail to return the response, after which a resend can execute the operation again ^7^. Preventing a client-library retry would not remove ambiguity caused by failures elsewhere, including proxies, gateways, or server-side components.

    For your stated operation, HTTP GET is defined as safe and idempotent: processing the same GET multiple times should not change resource state ^8^. If this particular endpoint gives GET a side effect, it does not conform to those semantics and should be redesigned.

    For operations where duplicate processing matters:

    1. Assign each logical operation a unique immutable identifier.
    2. Send it as an idempotency key or operation ID.
    3. Persist that key atomically on the server.
    4. Return the stored result when the same key appears again instead of repeating the side effect.

    This provides effectively-once processing despite uncertain delivery; eliminating duplicate delivery across a distributed system is generally impractical ^9^.

    Client choice

    Microsoft recommends migrating new development from HttpWebRequest to HttpClient because the former is obsolete ^10^. That migration is appropriate for maintainability and explicit handler configuration, but the supplied documentation does not establish that HttpClient on Windows PowerShell 5.1 guarantees one physical transmission either.

    If proof of the behavior of your exact patched runtime is required, capture both sides of a controlled test:

    • Client-side packet trace.
    • Server access/application log containing a unique correlation ID.
    • Injected stale keep-alive connections, resets, and response loss.
    • Exact System.dll file version and hash recorded with the results.

    Such testing can characterize that build under tested failures, but it cannot turn an internal implementation detail into a supported contractual guarantee.


    References

    1. referencesource/System/net/System/Net/HttpWebRequest.cs at main · microsoft/referencesource · GitHub
    2. HttpWebRequest._AutoRedirects Field
    3. HttpWebRequest.AllowAutoRedirect Property-Definition
    4. HttpWebRequest.KeepAlive Property-Definition
    5. HttpWebRequest.PreAuthenticate Property-Definition
    6. HttpWebRequest.GetResponse Method-Definition
    7. Retry pattern
    8. HTTP support in .NET
    9. Idempotent Consumer pattern
    10. HttpWebRequest to HttpClient migration guide
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

    1 person found this answer helpful.
  2. Bruce (SqlWork.com) 85,421 Reputation points
    2026-11-18T16:51:20.3166667+00:00

    the retry logic is mostly for the connection (stale ipaddress bindings). as ntlm authentication requires an out of band data exchange and new connection request, the retry logic is used for the reconnect. the retry logic is also used to follow a 401 response.

    if the called server is coded correctly, the WebRequest retry logic should not cause double processing of the request. as suggested, gateways, firewalls and caching servers may have more impact.

    also as suggested, if the WebRequest fails, the client has no way to know if the server processed the request or not. the usual solution is to implement idempotent requests, or pass a transaction guid, and the server uses the guid to check for a duplicate request.

    Was this answer helpful?

    0 comments No comments

  3. Nguyen Dam (WICLOUD CORPORATION) 1,740 Reputation points Microsoft External Staff Moderator
    2026-11-19T03:09:43.7733333+00:00

    Hello @Cinthia Franco , and thank you for your question. 

    In .NET Framework 4.8, a single application-level call to GetResponse() does not necessarily correspond to exactly one HTTP request being transmitted, as HttpWebRequest can resend a request internally in some situations. 

    Regarding your questions: 

    • On whether a GET can be retransmitted internally, and under what conditions: yes, it can. The Reference Source shows resubmission paths for cases such as a reused (keep-alive) connection failing, or a pipelining failure. However, Microsoft does not publish a complete list of the conditions under which this can happen, so I can't confirm that these are the only cases. 
    • On whether AllowAutoRedirect=false, KeepAlive=false, PreAuthenticate=false and Credentials=null prevent internal retries: these reduce some of those scenarios. For example, KeepAlive=false avoids reusing a persistent connection, and AllowAutoRedirect=false stops 3xx responses from being followed. But none of these settings is documented as disabling internal retransmission altogether. 
    • On whether there is a supported setting or way to guarantee at most one transmission: not that I'm aware of. HttpWebRequest has no documented property or configuration that provides this guarantee. 

    As for whether the Reference Source matches your installed System.dll, you can check this directly. Running [System.Net.HttpWebRequest].Assembly.Location in your PowerShell 5.1 session shows which System.dll is loaded. You can then inspect HttpWebRequest in that assembly using Visual Studio's built-in decompilation, or Ildasm.exe if you prefer to view the IL (since Ildasm doesn't work on files in the global assembly cache, copy the DLL to a separate folder first), and compare the retry-related logic, such as m_Retry, with the source. This shows how your current build is implemented, but it is not a supported guarantee and may change with future updates. 

    If you need to avoid duplicate requests, it is more reliable to handle this on the application or server side, for example by sending a unique request identifier and having the server detect repeats. This also covers the case where the server received the request but the response was lost, which the client alone cannot distinguish from a request that never arrived. 

    If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation. Thank you. 

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.