[英]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.