[英]CInternetSession::OpenURL on Windows Mobile causes error 12029 (cannot connect)
我试图通过在Windows Mobile 5上调用CInternetSession :: OpenUrl(使用MFC在C ++中进行编码)使用HTTP访问数据。 我总是收到错误代码为12029的异常(无法连接)。
我怀疑我需要首先使用连接管理器API创建连接。 有人可以确认吗?
我将根据此处的信息( http://msdn.microsoft.com/zh-cn/magazine/dd263096.aspx )尝试对其进行编码,如果合适,我将报告我的经验作为答案。 也可以得到其他输入。
我已经使用以下代码成功打开了连接:
// Find out which type of connection is needed for this URL.
GUID guid;
HRESULT hresult = ConnMgrMapURL((LPCTSTR)url,&guid,NULL);
if (!SUCCEEDED(hresult))
{
delete [] url;
aError = CartoType::KErrorInternetIo;
return NULL;
}
// Get a connection.
CONNMGR_CONNECTIONINFO cinfo;
memset(&cinfo,0,sizeof(cinfo));
cinfo.cbSize = sizeof(cinfo);
cinfo.bDisabled = FALSE;
cinfo.bExclusive = FALSE;
cinfo.guidDestNet = guid;
cinfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
cinfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
cinfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
DWORD status;
hresult = ConnMgrEstablishConnectionSync(&cinfo,&iConnectionHandle,15000,&status);
而且我知道它起作用是因为它将状态设置为CONNMGR_STATUS_CONNECTED
; 但是,此后我立即调用CInternetSession::OpenURL
并引发异常。
这是一些有效的代码。 它使用较低级别的Windows API,而不是MFC。 也许它不是理想的并且包含冗余(我真的需要ConnMgr调用吗?),但是它确实起作用:
// Find out which type of connection is needed for this URL.
GUID guid;
HRESULT hresult = ConnMgrMapURL((LPCTSTR)url,&guid,NULL);
if (!SUCCEEDED(hresult))
{
delete [] url;
aError = CartoType::KErrorInternetIo;
return NULL;
}
// Get a connection.
CONNMGR_CONNECTIONINFO cinfo;
memset(&cinfo,0,sizeof(cinfo));
cinfo.cbSize = sizeof(cinfo);
cinfo.bDisabled = FALSE;
cinfo.bExclusive = FALSE;
cinfo.guidDestNet = guid;
cinfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
cinfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
cinfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
DWORD status;
hresult = ConnMgrEstablishConnectionSync(&cinfo,&iConnectionHandle,15000,&status);
HINTERNET hinternet = InternetOpen(_T("CartoType"),INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
HINTERNET hfile = InternetOpenUrl(hinternet,(LPCTSTR)url,NULL,0,0,1);
这将返回一个有效的句柄,我可以使用InternetReadFile读取该句柄,然后使用InternetCloseHandle关闭它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.