Share via

WinHttpSetTimeouts did not work, WinHttpSendRequest can not return

Anonymous
2025-10-29T10:35:14.9266667+00:00

When I use WinHttp in a synchronisation model, sometimes the WinHttpSendRequest can not return.

Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.

0 comments No comments

Answer accepted by question author
  1. Susmitha T (INFOSYS LIMITED) 2,685 Reputation points Microsoft External Staff
    2025-10-30T10:42:08.4+00:00

    Thanks for reaching out!

    WinHttpSetTimeouts controls only specific phases (DNS resolve, connect, send, and receive) and does not cover the entire HTTP/HTTPS lifecycle, such as SSL handshake or proxy auto-detection. If asynchronous mode isn't an option, kindly check the alternatives below:

    1.Worker Thread+ Manual Timeout: Run the synchronous request in a separate thread and use a timer to call WinHttpCloseHandle( ) if it exceeds your custom timeout. This effectively simulates a global timeout.

    2.Status Callback: Register a callback using WinHttpSetStatusCallBack() to log and identify which stage the request hangs on.

    3.Disable Auto Proxy Detection (WPAD): Use WINHTTP_ACCESS_TYPE_NO_PROXY or a fixed proxy setting to avoid indefinite waits during proxy discovery.

    4.Pre-resolve DNS and Rescue Connections: Avoid repeated DNS or TCP setups where possible to reduce hang risks.

    References: WinHttpSetTimeouts function (winhttp.h) - Win32 apps | Microsoft Learn

    https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpsendrequest

    Let me know if you need any further help with this. I will be happy to assist.

    If you find this helpful, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.  

    1 person found this answer helpful.
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2025-10-31T01:12:57.3466667+00:00

    thanks for your reply.

    for "1.Worker Thread+ Manual Timeout: Run the synchronous request in a separate thread and use a timer to call WinHttpCloseHandle( ) if it exceeds your custom timeout. This effectively simulates a global timeout."
    this solution is multiple thread safe? I mean "WinHttpCloseHandle" is called in different thread with "Run the synchronous request in a separate thread", for example: call "WinHttpCloseHandle" in main thread, the worker thread will throw any exception in some cases?


  2. Anonymous
    2025-10-30T04:06:59.6533333+00:00

    WinHttpSetTimeouts already had been called in right way, but the issue still persist.
    Does the WinHttpSetTimeouts can control all the http/https life timeout?
    Is there any other solution except asynchronous mode?

    0 comments No comments

  3. Susmitha T (INFOSYS LIMITED) 2,685 Reputation points Microsoft External Staff
    2025-10-29T11:50:19.2933333+00:00

    Thanks for reaching out!

     
    WinHttpSendRequest may hang in synchronous mode if timeouts aren't applied correctly. Please ensure WinHttpSetTimeouts is called right after WinHttpOpen() and before WinHttpSendRequest(). If issue still persist, consider using asynchronous mode or adding a status callback (WinHttpSetStatusCallBack) to identify where it stalls.

     

    WinHttpSetTimeouts function (winhttp.h) - Win32 apps | Microsoft Learn

     

    Let me know if you need any further help with this. I will be happy to assist.

    If you find this helpful, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    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.