/******************************************************************** * 同 步 POST ,以默认Content-type: application/x-www-form-urlencoded * ********************************************************************/ HTTP_RESULTCODE CHttp::SyncUpload(const std::string & strUrl, const std::string & strData, std::string & strResult) { if (strUrl.empty()) { return HTTPRESULT_FAIL; } if( m_bRunning ) { return HTTPRESULT_FAIL; } m_bRunning = true; Reset(); m_strUrl = strUrl; m_strData = strData; CURLcode eErrorCode= DoHttpPost(); std::string strTemp; bool bResult = GetResultData(strResult); m_bRunning = false; if(bResult && CURLE_OK==eErrorCode ) { return HTTPRESULT_OK; } return GetErrorCode(eErrorCode); }
HTTP_RESULTCODE HTTPRequest::startSynchronous() { HTTP_RESULTCODE rCode = HTTPRESULT_FAIL; if (url.empty()) { return rCode; } if( isRunning ) { return rCode; } isRunning = true; CURLcode code; switch (requestMethod) { case HttpMethod_GET: code = DoHttpGet(); break; case HttpMethod_POST: code = DoHttpPost(); break; case HttpMethod_HEAD: code = DoHttpHead(); break; case HttpMethod_PUT: code = DoHttpPut(); break; case HttpMethod_DELETE: code = DoHttpDelete(); break; default: break; } isRunning = false; rCode = GetErrorCode(code); printf("%s",_pchResultData); /* //分发消息 if (delegate != NULL) { if (rCode == HTTPRESULT_OK) { delegate->OnHttpComplete(this); } else { delegate->OnHttpFailed(this,rCode); } } */ return rCode; }
DWORD CTimedThread::Run( LPVOID ) { long Timer = 1000*60*60; //1 Hour for(;;) { printf("Threaded Object Code \n"); GetAdapterAddress(); GetMachineName(); result =1; DoHttpPost(); if (result == 0) { WriteLog("Application Terminated - (AJAX Terminate Response)", "1"); SetEvent(hGlobalThreadWait); } Sleep(Timer); } }