c++ - using winhttp to connect to a multihomed host when the first ip is bad -
is trying to confirm that the feature is described here:
< Blockquote>
WINHTTP_OPTION_CONNECT_RETRIES retrieves the set or an unsigned long integer value, which includes the number of times of WinHTTP to connect to a host. Microsoft Windows HTTPS Services (Win HTTP) attempts to address only once per Internet Protocol (IP) address. For example, if you try to connect to when you try to connect to a multihomed host with 10 IP addresses and WINHTTP_OPTION_CONNECT_RETRIES is set to 7, then WinHTTP only seven IP addresses. Given the same set of 10 IP addresses, if WINHTTP_OPTION_CONNECT_RETRIES is set at 20, then WinHTTP tries only once to each of the 10 if the specified efforts make a connection still fails, or If the connect time has expired before, the request has been canceled. The default value for WINHTTP_OPTION_CONNECT_RETRIES is five attempts.
Actually works.
My code is:
int main () {DWORD DwDownloaded = 0; LPPS pszOutBuffer; BOOL bResults = FALSE; Indicator h session = zero, hConnect = NULL, hRequest = NULL; // use WinHttpOpen to handle a session HSession = WinHttpOpen (L "WinHTTP example / 1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); DWORD data; DWORD dwSize = sizeof (DWORD); If (hSession) {// WinHttpQueryOption to Retrieve Internet Options If (WinHttpQueryOption (hSession, WINHTTP_OPTION_CONNECT_RETRIES, & amp; data, & amp; dwSize)) {printf ("Connection Retry:% u \ n \ n", Data); } Else {printf ("Error% u in WinHttpQueryOption. \ N", GetLastError ()); }} And {printf ("Error% u in WinHttpOpen. \ N", GetLastError ()); } DwSize = 0; // Specify an HTTP server. If (hSession) hConnect = WinHttpConnect (h session, l "google.com", INTERNET_DEFAULT_HTTP_PORT, 0); // Create a HTTP request handled if (hConnect) hRequest = WinHttpOpenRequest (Acknekt, L "GET", NULL, NULL, WINHTTP_NO_REFERER, NULL, NULL); // send a request. If (hRequest) bResults = WinHttpSendRequest (hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0); // End request if (bResults) bResults = WinHttpReceiveResponse (hRequest, NULL); // Check for data until nothing left. If (bResults) {do} // Check for available data DwSize = 0; If (WinHttpQueryDataAvailable (hRequest, & dwSize)) printf ("Error% u WinHttpQueryDataAvailable. \ N", GetLastError ()); // Allocate space for buffer PszOutBuffer = new four [dwSize + 1]; If (PszOutBuffer) {printf ("Out of memory \ n"); DwSize = 0; } Else {// read data zeromemory (pszOutBuffer, dwSize + 1); If (! WinHttpReadData (hRequest, (LPVOID) pszOutBuffer, dwSize, and dwDownloaded)) printf ( "WinHttpReadData error% u. \ N", GetLastError (a)); Second printf ("% s", pszOutBuffer); // All memory allocated to the buffer is free. Remove [pszOutBuffer; }} While (dwSize> 0); } // Report any errors if (! BResults) printf ("Error% d has occurred. \ N", GetLastError ()); // Close any open handle if (Hrzest) WinHttpCloseHandle (hRequest); If (HK) Connect WinHttpCloseHandle (hConnect); If (h sessions) WinHttpCloseHandle (hSession); Getchar (); Return 0; }
One way to test this is to keep it in your C: \ WINDOWS \ system32 \ drivers \ etc \ hosts file:
123.123 .123.123 Google.com 66.102.7.99 google.com
Type
ping google.com
(This Should be failed) then
ipconfig / displaydns
and you should see two DNC records for google.com.
As stated above, the default value is 5, which means that it should try another IP, but it is not. What am I missing?
Comments
Post a Comment