winhttpsendrequest POST with https on windows server 2008 rc
winhttpsendrequest POST with https on windows server 2008 rc2
我正在编写一个Visual c ++应用程序,该应用程序应该向https端点发送http post消息(https服务器的证书是自签名的)。有 2 组客户端,一组在 Windows 7 PC 上,另一组在 Windows Server 2008 rc2 上。使用 mmc 控制台/管理单元(在两个 PC 组上)导入服务器的自签名证书后,Windows 7 PC 可以建立连接而不会出错,但在 Windows Server 2008 rc2 计算机上,错误 12030 始终由 winhttpsendrequest() 调用返回。有什么想法可以解决这个问题吗?任何帮助/提示将不胜感激。提前谢谢。我的代码如下。
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
hSession = WinHttpOpen( userAgent,
WINHTTP_ACCESS_TYPE_NO_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0 );
if( hSession ){
hConnect = WinHttpConnect( hSession, hostname, port, 0 );
if( hConnect ){
hRequest = WinHttpOpenRequest( hConnect, L"POST", urlPath,
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_REFRESH|WINHTTP_FLAG_SECURE );
if(hRequest){
AutoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT;
AutoProxyOptions.dwAutoDetectFlags = WINHTTP_AUTO_DETECT_TYPE_DHCP|WINHTTP_AUTO_DETECT_TYPE_DNS_A;
AutoProxyOptions.fAutoLogonIfChallenged = TRUE;
if( WinHttpGetProxyForUrl( hSession,
fullURL,
&AutoProxyOptions,
&ProxyInfo))
{
printf("proxy infon");
printf("access type: %ldn",ProxyInfo.dwAccessType);
printf("list: %sn",ProxyInfo.lpszProxy);
printf("bypass list: %sn",ProxyInfo.lpszProxyBypass);
if( !WinHttpSetOption( hRequest,
WINHTTP_OPTION_PROXY,
&ProxyInfo,
cbProxyInfoSize ) )
{
printf("Proxy detection logic failedn");
goto Exit;
}
}
else
{
printf("WinHttpGetProxyForUrl() returned [%d].. no proxy is used?n", GetLastError());
}
bResults = WinHttpSendRequest(hRequest, L"Content-Type:application/x-www-form-urlencoded", 0, (LPVOID)postRequest, data_len, data_len, 0);
if ( bResults != TRUE) {
wprintf(L"WinHttpSendRequest failed (%d)n", GetLastError());
}
else
{
//all good
bResults = WinHttpReceiveResponse( hRequest, NULL );
if( bResults )
{
do
{
dwSize = 0;
if( !WinHttpQueryDataAvailable( hRequest, &dwSize ) )
printf( "Error %u in WinHttpQueryDataAvailable.n", GetLastError());
pszOutBuffer = new char[dwSize+1];
if( !pszOutBuffer )
{
printf( "Out of memoryn" );
dwSize=0;
}
else
{
ZeroMemory( pszOutBuffer, dwSize+1 );
if( !WinHttpReadData( hRequest, (LPVOID)pszOutBuffer, dwSize, &dwDownloaded ) )
printf( "Error %u in WinHttpReadData.n", GetLastError( ) );
else{
printf( "From server [");
printf( "%s", pszOutBuffer );
printf("]n");
}
delete [] pszOutBuffer;
}
} while( dwSize > 0 );
}
}
}
else
{
wprintf(L"WinHttpOpenRequest failed (%d)n", GetLastError());
}
}
}
> 12030 是这样的:
ERROR_INTERNET_CONNECTION_ABORTED
12030
The connection with the server has been terminated.
这似乎不仅仅是身份验证或证书错误。
您是否尝试过检查服务器日志以查看它如何处理连接? 和小提琴手一起观察交通?
若要排除身份验证步骤作为问题,请尝试传递此处讨论的一些 SECURITY_FLAG_IGNORE_CERT_* 标志。
此外,请考虑使用 WinInet API 而不是 WinHTTP。 使用前者进行某些操作会更容易一些。
相关文章:
- VisualStudio:使用 Suse Enterprise Server 12 SP5 时,不会下载远程库标头
- 枚举和二进制或运算符(MISRA C++ 2008,4-5-2)
- 如何在 Windows 2016 Server 版本 1607 中访问 SetThreadDescription()
- 如何使用Visual Studio 2008将字符串映射到函数?
- 使用 SQLConfig数据源创建 SQL Server DSN 失败:关键字-值对无效
- Windows Server 2008 R2上的蓝牙GetradioInfo的替代方案
- 如何与SQL Server 2008建立稳定的连接,并在C 中编码我的第一个CRUD操作
- 为什么我不能在Windows Server 2008中使用System()从服务启动批处理文件
- Windows Server 2008 R2上的常见对话框:GetOpenFileName崩溃
- 在Windows Server 2008上挂接SMB文件操作
- visual C++ ODBC SQL Server 2008 Connection
- 用VS2012编写C++程序在Server 2008上不起作用
- winhttpsendrequest POST with https on windows server 2008 rc
- 调试.dll C++时出现MS SQL Server 2008错误17058
- SqlDependency issues, Visual C++ .Net 3.5, SQL Server 2008
- GetTokenInformation在windows server 2003上失败(错误998),但在2008上工作
- windows server 2008上的c++ fopen错误
- sql server 2008-如何使用ADO从c++调用用户定义的函数
- SQL Server 2008,数字库,c ++,LAPACK,内存问题
- CopyFile/CopyFileEx不能在Windows Server 2008 R2 SP1 x64中工作