本文整理汇总了C++中CHttpFile::SetOption方法的典型用法代码示例。如果您正苦于以下问题:C++ CHttpFile::SetOption方法的具体用法?C++ CHttpFile::SetOption怎么用?C++ CHttpFile::SetOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHttpFile
的用法示例。
在下文中一共展示了CHttpFile::SetOption方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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)
//.........这里部分代码省略.........