本文整理汇总了C++中CInternetSession::SetOption方法的典型用法代码示例。如果您正苦于以下问题:C++ CInternetSession::SetOption方法的具体用法?C++ CInternetSession::SetOption怎么用?C++ CInternetSession::SetOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CInternetSession
的用法示例。
在下文中一共展示了CInternetSession::SetOption方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UploadFile
//负责接收上传操作的页面的URL ,待上传的本地文件路径
int CWebBase::UploadFile(LPCTSTR strURL, LPCTSTR strLocalFileName)
{
ASSERT(strURL != NULL && strLocalFileName != NULL);
BOOL bResult = FALSE;
DWORD dwType = 0;
CString strServer;
CString strObject;
INTERNET_PORT wPort = 0;
DWORD dwFileLength = 0;
char * pFileBuff = NULL;
CHttpConnection * pHC = NULL;
CHttpFile * pHF = NULL;
CInternetSession cis;
bResult = AfxParseURL(strURL, dwType, strServer, strObject, wPort);
if(!bResult)
{
return FALSE;
}
CFile file;
try
{
if(!file.Open(strLocalFileName, CFile::shareDenyNone | CFile::modeRead))
return FALSE;
dwFileLength = file.GetLength();
if(dwFileLength <= 0)
return FALSE;
pFileBuff = new char[dwFileLength];
memset(pFileBuff, 0, sizeof(char) * dwFileLength);
file.Read(pFileBuff, dwFileLength);
const int nTimeOut = 5000;
cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, nTimeOut); //联接超时设置
cis.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 1); //重试1次
pHC = cis.GetHttpConnection(strServer, wPort); //取得一个Http联接
pHF = pHC->OpenRequest(CHttpConnection::HTTP_VERB_POST, strObject);
if(!pHF->SendRequest(NULL, 0, pFileBuff, dwFileLength))
{
delete[]pFileBuff;
pFileBuff = NULL;
pHF->Close();
pHC->Close();
cis.Close();
return FALSE;
}
DWORD dwStateCode = 0;
pHF->QueryInfoStatusCode(dwStateCode);
if(dwStateCode == HTTP_STATUS_OK)
bResult = TRUE;
}
catch(CInternetException * pEx)
{
char sz[256] = "";
pEx->GetErrorMessage(sz, 25);
CString str;
str.Format("InternetException occur!\r\n%s", sz);
AfxMessageBox(str);
}
catch(...)
{
DWORD dwError = GetLastError();
CString str;
str.Format("Unknow Exception occur!\r\n%d", dwError);
AfxMessageBox(str);
}
delete[]pFileBuff;
pFileBuff = NULL;
file.Close();
pHF->Close();
pHC->Close();
cis.Close();
return bResult;
}
示例2: sizeof
//.........这里部分代码省略.........
::UnlockResource(hGlobal);
::FreeResource(hGlobal);
}//
FindClose(hFind);//
g_strDatabasefilepath=(CString)FOR_DATABASE_CONNECT+g_strDatabasefilepath;//
g_strImgeFolder=g_strExePth+_T("Database\\image\\");//
CreateDirectory(g_strImgeFolder,NULL);//
JudgeDB();
//CString strocx=g_strExePth+_T("MSFLXGRD.OCX");
/*CStdioFile file;
CString versionno;
file.
file.SetFilePath(_T("http://www.temcocontrols.com/ftp/software/T3000_Version.txt"));
file.ReadString(versionno);
file.Close();*/
//CFile file;
// file.Open(_T("http://www.temcocontrols.com/ftp/software/T3000_Version.txt"),modeRead);
InitModeName();//
#if 0
CInternetSession session;
CInternetFile *file=NULL;
try
{
INTERNET_PROXY_INFO proxyinfo;
proxyinfo.dwAccessType=INTERNET_OPEN_TYPE_PROXY;
proxyinfo.lpszProxy=_T("192.168.0.4:8080 ");
proxyinfo.lpszProxyBypass=NULL;
if (!session.SetOption(INTERNET_OPTION_PROXY,(LPVOID)&proxyinfo,sizeof(INTERNET_PROXY_INFO)))
{
AfxMessageBox(_T("UserName"));
}
CString username=_T("alex");
if(!session.SetOption(INTERNET_OPTION_PROXY_USERNAME,username.GetBuffer(),username.GetLength()+ 1)){
AfxMessageBox(_T("UserName"));
}
CString password=_T("travel");
if(!session.SetOption(INTERNET_OPTION_PROXY_PASSWORD,password.GetBuffer(),password.GetLength()+ 1)){
AfxMessageBox(_T("Password"));
}
file=(CInternetFile*)session.OpenURL(_T("www.temcocontrols.com/ftp/software/T3000_Version.txt"));
}
catch (CInternetException* e)
{
file=NULL;
e->Delete();
}
CString version;
if (file)
{
while(file->ReadString(version)!=NULL){
}
AfxMessageBox(version);
}
#endif
示例3: GetHttp
CHAR* WebFetcher::GetHttp(LPCSTR lpServerName)
{
// start download file
char *pBuf = NULL ;
int nBufLen = 0 ;
TRY
{
// connection
CInternetSession sess ;
sess.SetOption (INTERNET_OPTION_CONNECT_TIMEOUT, 30 * 1000) ;
sess.SetOption (INTERNET_OPTION_CONNECT_BACKOFF, 1000) ;
sess.SetOption (INTERNET_OPTION_CONNECT_RETRIES, 1) ;
DWORD dwFlag = INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_RELOAD ;
CHttpFile * pF = (CHttpFile*)sess.OpenURL(lpServerName, 1, dwFlag); ASSERT(pF);
if (!pF)
{AfxThrowInternetException(1);}
// connection status
CString str ;
pF->QueryInfo (HTTP_QUERY_STATUS_CODE, str) ;
// Proxy Authentication Required
if (str == _T("407"))
{
CString strUsername, strPassword ;
// pPara->pThis->df_Notify (GetMsg_ProxyValidate(), &WM_DLF_PROXY_VALIDATE(&lpServerName, &strUsername, &strPassword)) ;
pF->SetOption (INTERNET_OPTION_PROXY_USERNAME, (VOID*)(LPCTSTR)strUsername, strUsername.GetLength()) ;
pF->SetOption (INTERNET_OPTION_PROXY_PASSWORD, (VOID*)(LPCTSTR)strPassword, strPassword.GetLength()) ;
pF->SendRequest (NULL) ;
}
pF->QueryInfo (HTTP_QUERY_STATUS_CODE, str) ;
if (str != _T("200"))
{
pF->Close() ;
delete pF ;
AfxThrowInternetException(1);
}
// confirm update
pF->QueryInfo (HTTP_QUERY_LAST_MODIFIED, str) ;
/* if (!pPara->pThis->df_Notify (GetMsg_CheckTime(), &WM_DLF_CHECKTIME(&lpServerName, &str)))
{
pF->Close() ;
delete pF ;
AfxThrowInternetException(1);
}
*/
// start download
pF->QueryInfo (HTTP_QUERY_CONTENT_LENGTH, str) ; // file's length
// pPara->pThis->df_Notify (GetMsg_StartDownload(), &pPara->strFileURL) ;
if (_ttoi(str))
{
// know file's size
int nLen = (nBufLen = _ttoi(str)) ;
char * p = (pBuf = new char[nLen+8]) ;
ZeroMemory (p, nLen+8) ;
// while (IsWindow(pPara->pThis->GetSafeHwnd()))
while (true)
{
// download 8K every
int n = pF->Read (p, (nLen < 8192) ? nLen : 8192) ;
if (n <= 0)
break ; // success exit
p += n ; nLen -= n ;
//pPara->pThis->df_Notify (GetMsg_Progress(), &WM_DLF_PROGRESS(&pPara->strFileURL, nBufLen-nLen, nBufLen)) ;
}
// interrupted
if (nLen != 0)
{
delete[] pBuf;
pBuf=NULL;
nBufLen = 0 ;
}
}
else
{
// don't know file's size, save context to a temp file.
bstr_t strFile = QueryTempFilePath() ;
CFile outFile (strFile, CFile::modeCreate|CFile::modeReadWrite) ;
int n = (int)pF->GetLength() ;
while (n)
{
char * pa = new char[n] ;
n = pF->Read (pa, n) ;
outFile.Write (pa, n) ;
// pPara->pThis->df_Notify (GetMsg_Progress(), &WM_DLF_PROGRESS(&pPara->strFileURL, (int)outFile.GetLength(), 0)) ;
n = (int)pF->GetLength() ;
delete[] pa ;
}
outFile.Close() ;
// success
if (n == 0)
//.........这里部分代码省略.........
示例4: AuthWeb
BOOL CLoginDlg::AuthWeb()
{
CString csBuff;
char httpBuff[1024];
CString csHash;
CMD5 md5SPIP;
int nBytes;
unsigned char lpszBuffer[16];
// Authentication for web pages
TRY
{
CInternetSession session;
CString csIdSession, csSession;
csBuff.Empty();
memset(httpBuff, 0, 1024);
session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 1000);
session.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 3);
CFile* pf = session.OpenURL(URL_LOGIN_WEB, 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_RELOAD);
while(nBytes = pf->Read(httpBuff, 1024))
{
csBuff += httpBuff;
}
pf->Close();
if(csBuff.Find('/') != -1)
{
csSession = csBuff.Left(csBuff.Find('/'));
csIdSession = csBuff.Mid(csSession.GetLength()+1);
md5SPIP.SetContent(APP.m_csPassword + csSession);
memset(lpszBuffer, 0, 16);
md5SPIP.GetDigest(lpszBuffer);
csHash = md5SPIP.ConvertToAscii(lpszBuffer);
APP.m_bAuthWeb = TRUE;
TRY
{
CHttpConnection* phttp = session.GetHttpConnection(_T(RYZOM_HOST));
CHttpFile* pfile = phttp->OpenRequest(CHttpConnection::HTTP_VERB_POST, "/betatest/betatest_login_valid.php");
if(pfile)
{
CString csHeaders = _T("Content-Type: application/x-www-form-urlencoded");
CString csFormParams = _T("txtLogin="+APP.m_csLogin+"&digest="+csHash+"&idsession="+csIdSession);
TRY
{
csBuff.Empty();
pfile->SendRequest(csHeaders, (LPVOID)(LPCTSTR)csFormParams, csFormParams.GetLength());
UINT nRead = pfile->Read(csBuff.GetBuffer(15000), 14999);
csBuff.ReleaseBuffer();
csBuff.SetAt(nRead, 0);
if(csBuff.Find("/news/") == -1)
{
APP.m_bAuthWeb = FALSE;
}
}
CATCH_ALL(error)
{
APP.m_bAuthWeb = FALSE;
}
END_CATCH_ALL;
delete pfile;
}
else
{
APP.m_bAuthWeb = FALSE;
}
}
CATCH_ALL(error)
{
APP.m_bAuthWeb = FALSE;
}
END_CATCH_ALL;
}