本文整理汇总了C++中CAtlStringW::ReleaseBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ CAtlStringW::ReleaseBuffer方法的具体用法?C++ CAtlStringW::ReleaseBuffer怎么用?C++ CAtlStringW::ReleaseBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAtlStringW
的用法示例。
在下文中一共展示了CAtlStringW::ReleaseBuffer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strUrlW
CNetRequestImpl::CNetRequestImpl(const char* method, const String& strUrl)
{
pszErrFunction = NULL;
hInet = NULL, hConnection = NULL, hRequest = NULL;
memset(&uri, 0, sizeof(uri) );
m_pInstance = this;
CAtlStringW strUrlW(strUrl.c_str());
do
{
if ( !isLocalHost(strUrl.c_str()) && !SetupInternetConnection(strUrlW) )
{
pszErrFunction = L"SetupInternetConnection";
break;
}
hInet = InternetOpen(_T("rhodes-wm"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL );
if ( !hInet )
{
pszErrFunction = L"InternetOpen";
break;
}
DWORD dwUrlLength = 1024;
CAtlStringW strCanonicalUrlW;
if ( !InternetCanonicalizeUrl( strUrlW, strCanonicalUrlW.GetBuffer(dwUrlLength), &dwUrlLength, 0) )
{
pszErrFunction = _T("InternetCanonicalizeUrl");
break;
}
strCanonicalUrlW.ReleaseBuffer();
alloc_url_components( &uri, strCanonicalUrlW );
if( !InternetCrackUrl( strCanonicalUrlW, strCanonicalUrlW.GetLength(), 0, &uri ) )
{
pszErrFunction = L"InternetCrackUrl";
break;
}
hConnection = InternetConnect( hInet, uri.lpszHostName, uri.nPort, _T("anonymous"), NULL,
INTERNET_SERVICE_HTTP, 0, 0 );
if ( !hConnection )
{
pszErrFunction = L"InternetConnect";
break;
}
strReqUrlW = uri.lpszUrlPath;
strReqUrlW += uri.lpszExtraInfo;
hRequest = HttpOpenRequest( hConnection, CAtlStringW(method), strReqUrlW, NULL, NULL, NULL,
INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_CACHE_WRITE, NULL );
if ( !hRequest )
{
pszErrFunction = L"HttpOpenRequest";
break;
}
}while(0);
}
示例2: readHeaders
boolean CNetRequestImpl::readHeaders(Hashtable<String,String>& oHeaders)
{
oHeaders.clear();
CAtlStringW strHeaders;
DWORD dwLen = 0;
DWORD nIndex = 0;
if( !HttpQueryInfo( hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, null, &dwLen, &nIndex) )
{
DWORD dwErr = ::GetLastError();
if ( dwErr != ERROR_INSUFFICIENT_BUFFER )
{
pszErrFunction = L"HttpQueryInfo";
return false;
}
}
if( !HttpQueryInfo( hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, strHeaders.GetBuffer(dwLen), &dwLen, &nIndex) )
{
pszErrFunction = L"HttpQueryInfo";
return false;
}
strHeaders.ReleaseBuffer();
int nStart = 0;
for(int nEnd = strHeaders.Find(L"\r\n", nStart); nEnd > 0; nStart = nEnd+2, nEnd = strHeaders.Find(L"\r\n", nStart) )
{
CAtlStringW strHeader = strHeaders.Mid(nStart, nEnd-nStart);
int nSep = strHeader.Find(':');
if (nSep < 0 )
continue;
CAtlStringW strName = strHeader.Mid(0, nSep);
strName.Trim();
strName.MakeLower();
CAtlStringW strValue = strHeader.Mid(nSep+1);
strValue.Trim();
oHeaders.put(common::convertToStringA(strName.GetString()),common::convertToStringA(strValue.GetString()));
}
return true;
}
示例3: ErrorMessage
void CNetRequestImpl::ErrorMessage(LPCTSTR pszFunction)
{
// Retrieve the system error message for the last-error code
LPTSTR pszMessage = NULL;
DWORD dwLastError = GetLastError();
DWORD dwLen = FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
//FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_FROM_HMODULE|
FORMAT_MESSAGE_IGNORE_INSERTS,
GetModuleHandle( _T("wininet.dll") ),
dwLastError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&pszMessage,
0, NULL );
CAtlStringW strExtError;
if ( dwLastError == ERROR_INTERNET_EXTENDED_ERROR )
{
DWORD dwInetError =0, dwExtLength = 0;
InternetGetLastResponseInfo( &dwInetError, NULL, &dwExtLength );
if ( dwExtLength > 0 )
{
InternetGetLastResponseInfo( &dwInetError, strExtError.GetBuffer(dwExtLength+1), &dwExtLength );
strExtError.ReleaseBuffer();
}
}
rho::LogMessage oLogMsg(__FILE__, __LINE__, L_ERROR, LOGCONF(), getLogCategory() );
oLogMsg + "Call " + pszFunction + " failed. With code : " + dwLastError;
if ( pszMessage )
oLogMsg + ".Message: " + pszMessage;
if ( strExtError.GetLength() )
oLogMsg + ".Extended info: " + strExtError.GetString();
if ( pszMessage )
LocalFree(pszMessage);
}
示例4: makeClientCookie
String CNetRequestImpl::makeClientCookie()
{
DWORD nIndex = 0;
String cookie;
while(true)
{
CAtlStringW strCookie;
DWORD dwLen = 0;
if( !HttpQueryInfo( hRequest, HTTP_QUERY_SET_COOKIE, null, &dwLen, &nIndex) )
{
DWORD dwErr = ::GetLastError();
if ( dwErr == ERROR_HTTP_HEADER_NOT_FOUND )
break;
if ( dwErr != ERROR_INSUFFICIENT_BUFFER )
{
pszErrFunction = L"HttpQueryInfo";
break;
}
}
if( !HttpQueryInfo( hRequest, HTTP_QUERY_SET_COOKIE, strCookie.GetBuffer(dwLen), &dwLen, &nIndex) )
{
pszErrFunction = L"HttpQueryInfo";
break;
}
strCookie.ReleaseBuffer();
URI::parseCookie(common::convertToStringA(strCookie.GetString()).c_str(), cookie);
}
if (pszErrFunction)
return "";
// if ( cookie.strAuth.length() > 0 || cookie.strSession.length() >0 )
// return cookie.strAuth + ";" + cookie.strSession + ";";
return cookie;
}
示例5: strUrlW
CNetRequestImpl::CNetRequestImpl(CNetRequest* pParent, const char* method, const String& strUrl, IRhoSession* oSession, Hashtable<String,String>* pHeaders)
{
m_pParent = pParent;
m_pParent->m_pCurNetRequestImpl = this;
m_pHeaders = pHeaders;
m_bCancel = false;
m_pSession = oSession;
pszErrFunction = NULL;
hInet = NULL, hConnection = NULL, hRequest = NULL;
memset(&uri, 0, sizeof(uri) );
m_strUrl = strUrl;
CAtlStringW strUrlW(strUrl.c_str());
LOG(INFO) + "Method: " + method + ";Url: " + strUrl;
do
{
if ( !URI::isLocalHost(strUrl.c_str()) && !SetupInternetConnection(strUrlW) )
{
pszErrFunction = L"SetupInternetConnection";
break;
}
hInet = InternetOpen(_T("rhodes-wm"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL );
if ( !hInet )
{
pszErrFunction = L"InternetOpen";
break;
}
DWORD dwUrlLength = 1024;
CAtlStringW strCanonicalUrlW;
if ( !InternetCanonicalizeUrl( strUrlW, strCanonicalUrlW.GetBuffer(dwUrlLength), &dwUrlLength, 0) )
{
pszErrFunction = _T("InternetCanonicalizeUrl");
break;
}
strCanonicalUrlW.ReleaseBuffer();
alloc_url_components( &uri, strCanonicalUrlW );
if( !InternetCrackUrl( strCanonicalUrlW, strCanonicalUrlW.GetLength(), 0, &uri ) )
{
pszErrFunction = L"InternetCrackUrl";
break;
}
hConnection = InternetConnect( hInet, uri.lpszHostName, uri.nPort, _T("anonymous"), NULL,
INTERNET_SERVICE_HTTP, 0, 0 );
if ( !hConnection )
{
pszErrFunction = L"InternetConnect";
break;
}
strReqUrlW = uri.lpszUrlPath;
strReqUrlW += uri.lpszExtraInfo;
DWORD dwFlags = INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_NO_COOKIES;
if ( uri.lpszScheme && wcsicmp(uri.lpszScheme,L"https")==0)
dwFlags |= INTERNET_FLAG_SECURE;
hRequest = HttpOpenRequest( hConnection, CAtlStringW(method), strReqUrlW, NULL, NULL, NULL, dwFlags, NULL );
if ( !hRequest )
{
pszErrFunction = L"HttpOpenRequest";
break;
}
if (oSession!=null)
{
String strSession = oSession->getSession();
LOG(INFO) + "Cookie : " + strSession;
if ( strSession.length() > 0 )
{
String strHeader = "Cookie: " + strSession + "\r\n";
if ( !HttpAddRequestHeaders( hRequest, common::convertToStringW(strHeader).c_str(), -1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE ) )
pszErrFunction = L"HttpAddRequestHeaders";
}
}
}while(0);
}