【问题标题】:WinHTTP Error 12029 Cannot ConnectWinHTTP 错误 12029 无法连接
【发布时间】:2013-07-11 15:12:24
【问题描述】:

我正在尝试与我自己的域建立 http 连接并返回一个字符串。我让它与 www.microsoft.com 合作,但是当我将域更改为 www.atomic-gaming.info(我的域)时,我收到错误 12029,如果我将链接更改为 www.yahoo.com,我收到错误 12017

代码

 DWORD dwSize = 0;
 DWORD dwDownloaded = 0;
 LPSTR pszOutBuffer;
 BOOL bResults = FALSE;
 HINTERNET hSession = NULL,  
 hConnect = NULL,
 hRequest = NULL;

 // Use WinHttpOpen to obtain a session handle.
 hSession = WinHttpOpen( L"WinHTTP Example/1.0",  
 WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
 WINHTTP_NO_PROXY_NAME,  
 WINHTTP_NO_PROXY_BYPASS, 0 );
 WinHttpSetOption(hSession, WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS,NULL,NULL);
 // Specify an HTTP server.
 if( hSession )
 hConnect = WinHttpConnect( hSession, L"www.microsoft.com",
 INTERNET_DEFAULT_HTTPS_PORT, 0 );

 // Create an HTTP request handle.
 if( hConnect )
 hRequest = WinHttpOpenRequest( hConnect, L"GET", NULL,
 NULL, WINHTTP_NO_REFERER,  
 WINHTTP_DEFAULT_ACCEPT_TYPES,  
 WINHTTP_FLAG_SECURE );

 // Send a request.
 if( hRequest )
 bResults = WinHttpSendRequest( hRequest,
 WINHTTP_NO_ADDITIONAL_HEADERS, 0,
 WINHTTP_NO_REQUEST_DATA, 0,  
 0, 0 );


 // End the request.
 if( bResults )
 bResults = WinHttpReceiveResponse( hRequest, NULL );

 // Keep checking for data until there is nothing left.
 if( bResults )
 {
 do  
 {
 // Check for available data.
 dwSize = 0;
 if( !WinHttpQueryDataAvailable( hRequest, &dwSize ) )
 printf( "Error %u in WinHttpQueryDataAvailable.\n",
 GetLastError( ) );

 // Allocate space for the buffer.
 pszOutBuffer = new char[dwSize+1];
 if( !pszOutBuffer )
 {
 printf( "Out of memory\n" );
 dwSize=0;
 }
 else
 {
 // Read the data.
 ZeroMemory( pszOutBuffer, dwSize+1 );

 if( !WinHttpReadData( hRequest, (LPVOID)pszOutBuffer,  
 dwSize, &dwDownloaded ) )
 printf( "Error %u in WinHttpReadData.\n", GetLastError( ) );
 else
 printf( "%s", pszOutBuffer );

 // Free the memory allocated to the buffer.
 delete [] pszOutBuffer;
 }
 } while( dwSize > 0 );
 }


 // Report any errors.
 if( !bResults )
 printf( "Error %d has occurred.\n", GetLastError( ) );

 // Close any open handles.
 if( hRequest ) WinHttpCloseHandle( hRequest );
 if( hConnect ) WinHttpCloseHandle( hConnect );
 if( hSession ) WinHttpCloseHandle( hSession );

谁能告诉我为什么这只适用于microsoft.com?我将如何解决它?

【问题讨论】:

  • 添加这些错误代码的含义可能更有帮助
  • @Waldermort 对于它的价值,12029 是 ERROR_WINHTTP_CANNOT_CONNECT 而 12017 是 ERROR_WINHTTP_OPERATION_CANCELLED
  • @IgorTandetnik 我希望鼓励发帖者首先使用 google 来识别错误,也许能让他深入了解他的问题可能是什么。另一方面,我真的希望 MS 使用枚举而不是错误代码,让它们更易于阅读。

标签: c++ windows connection winhttp


【解决方案1】:

您正在通过 HTTPS 进行连接。 www.atomic-gaming.info 没有提供有效的 SSL 证书,因此 WinHTTP 出于安全原因拒绝连接到它(这可以被覆盖)。

www.yahoo.com 重定向到 HTTP。它对您不起作用,因为您错误地调用了WinHttpSetOption。实现它

DWORD opt = WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS;
WinHttpSetOption(hSession, WINHTTP_OPTION_REDIRECT_POLICY, &opt, sizeof(opt));

【讨论】:

  • 一些网站出现错误 12029,atomic-gaming.info 出现 12175...现在有什么问题?
  • 以及我将如何覆盖 ssl 证书验证。
  • 12175 将是 ERROR_WINHTTP_SECURE_FAILURE。 Look it up. 您通过使用 WinHttpSetOption 将 WINHTTP_OPTION_SECURITY_FLAGS 选项设置为 desired combination of flags 来禁用证书检查
  • 我收到 12002,,,, 超时问题。不知道有什么错误感觉该网站仍然有效。在我的另一个域中,我尝试了所有方法并继续获得 12029
  • 我尝试使用这些选项。它们组合起来似乎都不起作用。该网站在我的网络浏览器上加载良好,它只是连接......
猜你喜欢
  • 2010-10-23
  • 1970-01-01
  • 1970-01-01
  • 2011-05-22
  • 1970-01-01
  • 1970-01-01
  • 2016-12-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多