The SetTimeouts method specifies the individual time-out components of a send/receive operation, in milliseconds.

C++
Syntax
|
HRESULT SetTimeouts(
[in] long ResolveTimeout,
[in] long ConnectTimeout,
[in] long SendTimeout,
[in] long ReceiveTimeout
);
|
Parameters
- ResolveTimeout
Value of type long integer. Time-out value applied when resolving a host name (such as www.microsoft.com) to an IP address (such as 192.168.131.199), in milliseconds. The default value is zero, meaning no time-out (infinite). If DNS timeout is specified using NAME_RESOLUTION_TIMEOUT, there is an overhead of one thread per request.
- ConnectTimeout
Value of type long integer. Time-out value applied when establishing a communication socket with the target server, in milliseconds. The default value is 60,000 (60 seconds).
- SendTimeout
Value of type long integer. Time-out value applied when sending an individual packet of request data on the communication socket to the target server, in milliseconds. A large request sent to an HTTP server are normally be broken up into multiple packets; the send time-out applies to sending each packet individually. The default value is 30,000 (30 seconds).
- ReceiveTimeout
Value of type long integer. Time-out value applied when receiving a packet of response data from the target server, in milliseconds. Large responses are be broken up into multiple packets; the receive time-out applies to fetching each packet of data off the socket. The default value is 30,000 (30 seconds).
Return Value
Returns S_OK if successful, or an error value otherwise.
Example Code
The following example shows how to set all WinHTTP time-outs to 30 seconds, open an HTTP connection, send an HTTP request, and read the response text. This example must be run from a command prompt.
|
#include "stdafx.h"
#include "objbase.h"
#include "httprequest.h"
// IID for IWinHttpRequest.
const IID IID_IWinHttpRequest =
{
0x06f29373,
0x5c5a,
0x4b54,
{0xb0, 0x25, 0x6e, 0xf1, 0xbf, 0x8a, 0xbf, 0x0e}
};
int main(int argc, char* argv[])
{
// variable for return value
HRESULT hr;
// initialize COM
hr = CoInitialize( NULL );
IWinHttpRequest * pIWinHttpRequest = NULL;
BSTR bstrResponse = NULL;
VARIANT varFalse;
VARIANT varEmpty;
CLSID clsid;
VariantInit(&varFalse);
V_VT(&varFalse) = VT_BOOL;
V_BOOL(&varFalse) = VARIANT_FALSE;
VariantInit(&varEmpty);
V_VT(&varEmpty) = VT_ERROR;
hr = CLSIDFromProgID(L"WinHttp.WinHttpRequest.5.1", &clsid);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(clsid, NULL,
CLSCTX_INPROC_SERVER,
IID_IWinHttpRequest,
(void **)&pIWinHttpRequest);
}
if (SUCCEEDED(hr))
{ // Set Time-outs.
hr = pIWinHttpRequest->SetTimeouts(30000, 30000,
30000, 30000);
}
if (SUCCEEDED(hr))
{ // Open WinHttpRequest.
BSTR bstrMethod = SysAllocString(L"GET");
BSTR bstrUrl = SysAllocString(L"http://microsoft.com");
hr = pIWinHttpRequest->Open(bstrMethod,
bstrUrl,
varFalse);
SysFreeString(bstrMethod);
SysFreeString(bstrUrl);
}
if (SUCCEEDED(hr))
{ // Send Request.
hr = pIWinHttpRequest->Send(varEmpty);
}
if (SUCCEEDED(hr))
{ // Get Response text.
hr = pIWinHttpRequest->GetAllResponseHeaders(&bstrResponse);
}
if (SUCCEEDED(hr))
{ // Print response to console.
wprintf(L"%.256s",bstrResponse);
}
// Release memory.
if (pIWinHttpRequest)
pIWinHttpRequest->Release();
if (bstrResponse)
SysFreeString(bstrResponse);
CoUninitialize();
return 0;
}
|

Script
Syntax
|
SetTimeouts(
ResolveTimeout,
ConnectTimeout,
SendTimeout,
ReceiveTimeout
) |
Parameters
- ResolveTimeout
Value of type long integer. Time-out value applied when resolving a host name (such as www.microsoft.com) to an IP address (such as 192.168.131.199), in milliseconds. The default value is zero, meaning no time-out (infinite). If DNS timeout is specified using NAME_RESOLUTION_TIMEOUT, there is an overhead of one thread per request.
- ConnectTimeout
Value of type long integer. Time-out value applied when establishing a communication socket with the target server, in milliseconds. The default value is 60,000 (60 seconds).
- SendTimeout
Value of type long integer. Time-out value applied when sending an individual packet of request data on the communication socket to the target server, in milliseconds. A large request sent to an HTTP server are normally be broken up into multiple packets; the send time-out applies to sending each packet individually. The default value is 30,000 (30 seconds).
- ReceiveTimeout
Value of type long integer. Time-out value applied when receiving a packet of response data from the target server, in milliseconds. Large responses are be broken up into multiple packets; the receive time-out applies to fetching each packet of data off the socket. The default value is 30,000 (30 seconds).
Return Value
This method does not return a value.
Example Code
The following example shows how to set all WinHTTP time-outs to 30 seconds, open an HTTP connection, and send an HTTP request.
|
// Instantiate a WinHttpRequest object.
var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
// Set time-outs. If time-outs are set, they must
// be set before open.
WinHttpReq.SetTimeouts(30000, 30000, 30000, 30000);
// Initialize an HTTP request.
WinHttpReq.Open("GET", "http://www.microsoft.com", false);
// Send the HTTP request.
WinHttpReq.Send(); |

Visual Basic
Syntax
|
Sub SetTimeouts( _
ByVal ResolveTimeout As long, _
ByVal ConnectTimeout As long, _
ByVal SendTimeout As long, _
ByVal ReceiveTimeout As long _
) |
Parameters
- ResolveTimeout
Value of type long integer. Time-out value applied when resolving a host name (such as www.microsoft.com) to an IP address (such as 192.168.131.199), in milliseconds. The default value is zero, meaning no time-out (infinite). If DNS timeout is specified using NAME_RESOLUTION_TIMEOUT, there is an overhead of one thread per request.
- ConnectTimeout
Value of type long integer. Time-out value applied when establishing a communication socket with the target server, in milliseconds. The default value is 60,000 (60 seconds).
- SendTimeout
Value of type long integer. Time-out value applied when sending an individual packet of request data on the communication socket to the target server, in milliseconds. A large request sent to an HTTP server are normally be broken up into multiple packets; the send time-out applies to sending each packet individually. The default value is 30,000 (30 seconds).
- ReceiveTimeout
Value of type long integer. Time-out value applied when receiving a packet of response data from the target server, in milliseconds. Large responses are be broken up into multiple packets; the receive time-out applies to fetching each packet of data off the socket. The default value is 30,000 (30 seconds).
Return Value
This method does not return a value.
Example Code
The following example shows how to set all WinHTTP time-outs to 30 seconds, open an HTTP connection, send an HTTP request, and read the response text. For this example to work, you must have a form containing a command button named Command1 and a text box named Text1. In addition, the Multiline property of Text1 must be set to TRUE.
|
Option Explicit
Private Sub Command1_Click()
Dim HttpReq As Object
' Create the WinHTTPRequest ActiveX Object.
Set HttpReq = New WinHttpRequest
' Switch the mouse pointer to an hourglass while busy.
MousePointer = vbHourglass
' Set time-outs. If time-outs are set, they must be
' set before open.
HttpReq.SetTimeouts 30000, 30000, 30000, 30000
' Open an HTTP connection.
HttpReq.Open "GET", "http://microsoft.com", False
' Send the HTTP Request.
HttpReq.Send
' Get all response headers.
Text1.Text = HttpReq.GetAllResponseHeaders()
' Switch the mouse pointer back to default.
MousePointer = vbDefault
End Sub
|
Remarks
All parameters are required. A value of 0 or -1 sets a time-out to wait infinitely. A value greater than 0 sets the time-out value in milliseconds. For example, 30,000 would set the time-out to 30 seconds. All negative values other than -1 cause this method to fail.
Time-out values are applied at the Winsock layer.
Note For Windows XP, Windows 2000, and Windows NT 4.0, see the Run-Time Requirements section of the WinHttp start page.
Requirements
| Client | Requires Windows Vista, Windows XP SP1, or Windows 2000 Professional SP3 and later. |
| Server | Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server SP3 and later. |
| Redistributable | Requires WinHTTP 5.0 and Internet Explorer 5.01 or later on Windows XP, Windows 2000, and Windows NT 4.0, and Windows NT 4.0. For more information, see the Remarks section. |
| IDL | Declared in HttpRequest.idl. |
| Library | Use Winhttp.lib. |
| DLL | Requires Winhttp.dll. |
See Also
IWinHttpRequest
WinHttpRequest
WinHTTP Versions
Send comments about this topic to Microsoft
Build date: 3/27/2008