环境:使用C / C ++(VS2008)的Windows Mobile Win32
我需要一种干净且 可靠的 方法,使用http将一些GPS坐标(或其他数据)更新到网络服务器。
目前我一直在使用以下代码:
wsprintf (threadParam.wszLocInfo, L"%s/LOGGPS/?U=%s&LAT=%.07f&LNG=%.07f&V=%s", ...);
HANDLE hHTTPthread = CreateThread ( NULL, // No security attributes in Windows CE.
0, // Initial thread stack size, in bytes (Must be 0 under Windows CE)
(LPTHREAD_START_ROUTINE) HTTPthread, // Thread procedure/function.
&threadParam, // The argument for the new thread
0, // Creation flags
NULL ); // Returned ID value (ignored).
// Wait for the worker thread to complete. (with timeout)
if (WaitForSingleObject (hHTTPthread, g_progSettings.dInetTimeout) == WAIT_TIMEOUT)
{
if (g_hHttpOpen)
InternetCloseHandle (g_hHttpOpen); // terminate session.
// Wait until the worker thread exits
WaitForSingleObject (hHTTPthread, INFINITE);
CloseHandle (hHTTPthread);
g_txtbox.print (L"Worker thread has exited.\r\n");
return 0;
}
/////////////////// WorkerFunction //////////////////////
DWORD WINAPI HTTPthread (IN LPVOID vThreadParam)
{
// Get pointer to thread parameters.
THREADPARAM *pThreadParam = (THREADPARAM*)vThreadParam;
// Initialize an application's use of the Win32 Internet functions.
g_hHttpOpen = InternetOpen (APP_CLASSNAME, // Application ID
INTERNET_OPEN_TYPE_DIRECT, // No proxy server access
NULL, // No name for proxy server
NULL, // No bypass addresses
0); // No flags - Typical
if (g_hHttpOpen == NULL)
return 1; // failure
// Set timeout. Whether they work or not, every bit might help.
InternetSetOption (g_hHttpOpen, INTERNET_OPTION_CONNECT_TIMEOUT, &g_progSettings.dInetTimeout, sizeof(DWORD));
InternetSetOption (g_hHttpOpen, INTERNET_OPTION_RECEIVE_TIMEOUT, &g_progSettings.dInetTimeout, sizeof(DWORD));
InternetSetOption (g_hHttpOpen, INTERNET_OPTION_SEND_TIMEOUT, &g_progSettings.dInetTimeout, sizeof(DWORD));
InternetSetOption (g_hHttpOpen, INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT, &g_progSettings.dInetTimeout, sizeof(DWORD));
InternetSetOption (g_hHttpOpen, INTERNET_OPTION_CONTROL_SEND_TIMEOUT, &g_progSettings.dInetTimeout, sizeof(DWORD));
InternetSetOption (g_hHttpOpen, INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, &g_progSettings.dInetTimeout, sizeof(DWORD));
InternetSetOption (g_hHttpOpen, INTERNET_OPTION_DATA_SEND_TIMEOUT, &g_progSettings.dInetTimeout, sizeof(DWORD));
g_hHttpUrl = InternetOpenUrl (g_hHttpOpen,
pThreadParam->wszLocInfo,
NULL,
0,
INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE,
0);
if (g_hHttpUrl == NULL)
{
InternetCloseHandle (g_hHttpOpen);
return 2; // failure
}
// clean-up.
InternetCloseHandle (g_hHttpOpen);
InternetCloseHandle (g_hHttpUrl);
return 0; // success
}
现在虽然这很有效(大多数情况下),但我们都知道超时是片状的,这种强力技术在任何时候都不是非常可靠和反应灵敏。
InternetOpenUrl(..)功能让事情变得简单,但它已经半生不熟,而且不够灵活。
所以我正在寻找一种替代方法来执行相同的操作。 具有可靠的超时。
你们是如何处理这些网络服务器更新的?
感谢。
答案 0 :(得分:0)
可能不是一个有用的答案,但我正在为我的移动应用程序使用WTL,它在CAtlHttpClientT中很好地完成了Web服务访问。但是,没有玩过更改SOAP请求的超时。