本文整理汇总了C++中CHttpFile::ReadString方法的典型用法代码示例。如果您正苦于以下问题:C++ CHttpFile::ReadString方法的具体用法?C++ CHttpFile::ReadString怎么用?C++ CHttpFile::ReadString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHttpFile
的用法示例。
在下文中一共展示了CHttpFile::ReadString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetFirstGoalUrl
BOOL CProxyIP::GetFirstGoalUrl(const TCHAR* pSrcUrl, TCHAR* pGoalUrl)
{
BOOL bRet = FALSE;
CHttpFile* pHttpFile = (CHttpFile *)m_pSession->OpenURL(pSrcUrl);
DWORD dwStatusCode = 0;
pHttpFile->QueryInfoStatusCode(dwStatusCode);
if (dwStatusCode == HTTP_STATUS_OK)
{
CString strData;
wstring subStr = _T("国内网页http代理ip地址服务器");
while(pHttpFile->ReadString(strData))
{
TCHAR mainStr[MAX_STR_LEN] = {0};
ConvertMultiByteToWideChar((char *)strData.GetBuffer(), mainStr, MAX_STR_LEN);
wstring wMainStr = mainStr;
if (wMainStr.find(subStr) < wMainStr.length())
{
int startLoc = wMainStr.find(_T("href"));
int endLoc = wMainStr.find(_T("title"));
endLoc -= 2;
startLoc += 6;
wstring wTempUrl = wMainStr.substr(startLoc, endLoc-startLoc).c_str();
wmemcpy(pGoalUrl, wTempUrl.c_str(), wcslen(wTempUrl.c_str())+1);
bRet = TRUE;
break;
}
}
}
pHttpFile->Close();
delete pHttpFile;
return bRet;
}
示例2: urlGet
std::string urlGet(const char* pUrl)
{
CInternetSession session(__argv[0]);
CHttpFile *file = NULL;
CString strHtml = ""; //存放网页数据
char* headers = "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;)" ;
try
{
file = (CHttpFile*)session.OpenURL(pUrl , 1 , INTERNET_FLAG_TRANSFER_ASCII , headers , strlen(headers)) ;
}
catch(CInternetException * m_pException){
file = NULL;
m_pException->Delete();
session.Close();
return "" ;
}
CString strLine;
if(file != NULL)
{
while(file->ReadString(strLine) != NULL)
{
strHtml += strLine;
//strHtml +="\n" ;
}
file->Close();
delete file;
file = NULL;
}
session.Close();
return std::string(strHtml) ;
}
示例3:
void C51JobWebPost::TestProxy()
{
CInternetSession session;
CHttpFile *file = NULL;
INTERNET_PROXY_INFO proxyinfo;
proxyinfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
proxyinfo.lpszProxy ="122.205.95.14:80";
proxyinfo.lpszProxyBypass = NULL;
session.SetOption(INTERNET_OPTION_PROXY,(LPVOID)&proxyinfo,
sizeof(INTERNET_PROXY_INFO));
try{
file = (CHttpFile*)session.OpenURL("http://www.ip138.com/ip2city.asp",1,
INTERNET_FLAG_TRANSFER_ASCII|INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE);
}catch(CInternetException * m_pException){
file = NULL;
m_pException->m_dwError;
m_pException->Delete();
session.Close();
AfxMessageBox("CInternetException");
return;
}
CString strLine;
CString strResult = "";
if(file != NULL){
while(file->ReadString(strLine) != NULL){
strResult += strLine;
}
}else{
AfxMessageBox("fail");
}
file->Close();
session.Close();
}
示例4: OnBtnSendpost
void CHttpPostDlg::OnBtnSendpost()
{
CInternetSession m_InetSession(_T("session"),
0,
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
INTERNET_FLAG_DONT_CACHE); //设置不缓冲
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
CString strHtml = "";
CString ActionServer = _T("www.cqjg.gov.cn");
CString strRequest = _T("LicenseTxt=AG8091&VIN=LJDAAA21560205432"); //POST过去的数据
CString strHeaders = "Accept: text*/*\r\nContent-Type: application/x-www-form-urlencoded\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon;";
int nRead = 0;
try
{
INTERNET_PORT nPort = 80; //端口
pServer = m_InetSession.GetHttpConnection(ActionServer, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,"/netcar/FindOne.aspx");
pFile->AddRequestHeaders(strHeaders);
pFile->SendRequestEx(strRequest.GetLength());
pFile->WriteString(strRequest); //重要-->m_Request 中有"name=aaa&name2=BBB&..."
pFile->EndRequest();
DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
if (dwRet == HTTP_STATUS_OK)
{
CString strLine;
while ((nRead = pFile->ReadString(strLine))>0)
{
strHtml += strLine + "\n";;
}
}
int pos = strHtml.Find(_T("<li class=\"lithreeC\">"));
if(pos != -1)
{
CString Value = strHtml.Mid(pos,500);
CFile file("test.html",CFile::modeCreate|CFile::modeWrite);
file.WriteHuge(Value.GetBuffer(0),Value.GetLength());
file.Close();
//MessageBox(Value);
}
delete pFile;
delete pServer;
}
catch (CInternetException* e)
{
char strErrorBuf[255];
e->GetErrorMessage(strErrorBuf,255,NULL);
AfxMessageBox(strErrorBuf,MB_ICONINFORMATION);
}
// SendPost();
}
示例5: mySession
CString CUpdateApp::GetWebStieHtml(CString strUrl)
{
CInternetSession mySession(NULL,0);
CHttpFile* myHttpFile = NULL;
myHttpFile = (CHttpFile*)mySession.OpenURL(strUrl);//str是要打开的地址
CString myData;
CString csHtmlContent;
while(myHttpFile->ReadString(myData))
{
csHtmlContent += myData;
}
return csHtmlContent;
}
示例6: userProfile
DWORD CLoginDlg::userProfile(LPCTSTR serverURL, LPCTSTR requestPage)
{
#ifdef _HTTPS
CInternetSession session(_T("HelloChat"), INTERNET_FLAG_SECURE);
CHttpConnection* pConnection = session.GetHttpConnection(serverURL, INTERNET_SERVICE_HTTP, INTERNET_DEFAULT_HTTPS_PORT);
CString strToken = L"token:";
strToken = strToken + m_strMyToken + L"\r\n";
CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, requestPage, NULL, 1, NULL, NULL, INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD |
INTERNET_FLAG_DONT_CACHE |
INTERNET_FLAG_NO_COOKIES);
#else
CInternetSession session(_T("HelloChat"), PRE_CONFIG_INTERNET_ACCESS);
CHttpConnection* pConnection = session.GetHttpConnection(serverURL);
CString strToken = L"token:";
//strToken = strToken + m_strToken + L"\r\n";
strToken = strToken + m_strMyToken + L"\r\n";
CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, requestPage, NULL, 1, NULL, NULL, INTERNET_FLAG_RELOAD |
INTERNET_FLAG_DONT_CACHE |
INTERNET_FLAG_NO_COOKIES);
#endif
VERIFY(pFile->AddRequestHeaders(HEADER));
VERIFY(pFile->AddRequestHeaders(strToken));
VERIFY(pFile->SendRequest());
// GET POST STATUS
DWORD dwPostStatus = 0;
VERIFY(pFile->QueryInfoStatusCode(dwPostStatus));
CString strBuffer = L"";
BOOL brtn = pFile->ReadString(strBuffer);
char* rtnBuffer = LPSTR(LPCTSTR(strBuffer));
if (dwPostStatus == HTTP_STATUS_OK)
{
BOOL bRtn = dataParser(rtnBuffer);
if (!bRtn){
AfxMessageBox(L"User Info Paser Error");
}
}
else{
CComm func;
func.WriteErrorLog(rtnBuffer);
}
pFile->Close();
return dwPostStatus;
}
示例7: FillGoalUrlVec
BOOL CProxyIP::FillGoalUrlVec(const TCHAR* pFirstGoalUrl)
{
BOOL bRet = FALSE;
int totalPage = 0;
CHttpFile* pHttpFile = (CHttpFile *)m_pSession->OpenURL(pFirstGoalUrl);
DWORD dwStatusCode = 0;
pHttpFile->QueryInfoStatusCode(dwStatusCode);
if (dwStatusCode == HTTP_STATUS_OK)
{
BOOL bCheck = FALSE;
CString strData;
wstring subStrPage = _T("class=\"pagelist\"");
while(pHttpFile->ReadString(strData))
{
TCHAR mainStr[MAX_STR_LEN] = {0};
ConvertMultiByteToWideChar((char *)strData.GetBuffer(), mainStr, MAX_STR_LEN);
wstring wMainStr = mainStr;
if (bCheck)
{
int lenn = wMainStr.find(_T("共"));
wstring wsPage = wMainStr.substr(lenn+1, 1).c_str();
totalPage = _wtoi(wsPage.c_str());
bCheck = FALSE;
break;
}
if (wMainStr.find(subStrPage) < wMainStr.length())
{
bCheck = TRUE;
}
}
wstring strGoalUrl = pFirstGoalUrl;
int lenHtml = strGoalUrl.find(_T(".html"));
wstring newStrGoalUrl = strGoalUrl.substr(0, lenHtml);
for (int j = 2; j <= totalPage; j++)
{
TCHAR tChar[MAX_URL_LEN] = {0};
swprintf(tChar, MAX_URL_LEN, _T("%s_%d.html"), newStrGoalUrl.c_str(), j);
m_goalUrlVec.push_back(tChar);
}
bRet = TRUE;
}
pHttpFile->Close();
delete pHttpFile;
return bRet;
}
示例8: GetTallyTBResponse
/* ===================================================================
* GET Tally TB Response for a given request
* ===================================================================
*/
BOOL CTallyExporterDlg::GetTallyTBResponse(CString& xmlTBRequestRef,vector<string>& allRowsOfTBRef, int port)
{
CInternetSession session(_T("TB Session"));
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
try
{
CString strServerName;
DWORD dwRet = 0;
CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded;Accept-Encoding: gzip,deflate");
CString acceptedTypes[] = {_T("text/html")};
pServer = session.GetHttpConnection(_T("localhost"),NULL, port, NULL, NULL);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, _T(""), NULL,1,(LPCTSTR*)acceptedTypes,NULL,INTERNET_FLAG_EXISTING_CONNECT);
pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR)xmlTBRequestRef, xmlTBRequestRef.GetLength());
pFile->QueryInfoStatusCode(dwRet);
CString csvLinesToBeRead;
CString& csvLinesToBeReadRef = csvLinesToBeRead;
if (dwRet == HTTP_STATUS_OK)
{
while (pFile->ReadString(csvLinesToBeReadRef) == TRUE)
{
allRowsOfTBRef.push_back((LPCTSTR)csvLinesToBeReadRef);
}
}
else
{
//Do something as server is not sending response as expected.
}
delete pFile;
delete pServer;
}
catch (CInternetException* pEx)
{
//catch errors from WinInet
TCHAR pszError[64];
pEx->GetErrorMessage(pszError, 64);
_tprintf_s(_T("%63s"), pszError);
}
session.Close();
return false;
}
示例9: GetSourceHtml
bool CWebpageHandler::GetSourceHtml(CString theUrl,CString fileName)
{
CInternetSession session;
CHttpFile *file = NULL;
CString strURL = theUrl;
CString strHtml = _T(""); //存放网页数据
try{
file = (CHttpFile*)session.OpenURL(strURL);
}catch(CInternetException * m_pException){
file = NULL;
m_pException->m_dwError;
m_pException->Delete();
session.Close();
MessageBox(_T("网络连接失败!"));
return false;
}
CString strLine;
if(file != NULL){
while(file->ReadString(strLine) != NULL){
strHtml += strLine;
}
}else{
MessageBox(_T("读取网络数据失败!"));
return false;
}
CFile file0(fileName, CFile::modeCreate|CFile::modeWrite);
int len = strHtml.GetLength()*2;
file0.Write(strHtml, len);
session.Close();
file->Close();
file0.Close();
delete file;
file = NULL;
m_htmlStr = strHtml;
m_url = theUrl;
return true;
}
示例10: FillIpVec
BOOL CProxyIP::FillIpVec()
{
int i = 0;
for (i = 0; i < m_goalUrlVec.size(); i++)
{
CHttpFile* pHttpFile = (CHttpFile *)m_pSession->OpenURL(m_goalUrlVec[i].c_str());
DWORD dwStatusCode = 0;
pHttpFile->QueryInfoStatusCode(dwStatusCode);
if (dwStatusCode == HTTP_STATUS_OK)
{
BOOL bCheck = FALSE;
CString strData;
wstring subStr = _T("class=\"cont_ad\"");
while(pHttpFile->ReadString(strData))
{
TCHAR mainStr[MAX_STR_LEN] = {0};
ConvertMultiByteToWideChar((char *)strData.GetBuffer(), mainStr, MAX_STR_LEN);
wstring wMainStr = mainStr;
if (bCheck)
{
if (wMainStr.find(_T("</span>")) < wMainStr.length())
{
break;
}
TCHAR firstPosChar = wMainStr.at(0);
if (firstPosChar < 48 || firstPosChar > 57)
{
continue;
}
m_IpVec.push_back(wMainStr);
m_totalIp++;
}
if (wMainStr.find(subStr) < wMainStr.length())
{
bCheck = TRUE;
}
}
}
pHttpFile->Close();
delete pHttpFile;
}
return TRUE;
}
示例11: GetStockInfo
CString StockRetriever::GetStockInfo(CString url)
{
CInternetSession inter_session;
CString strHtml;
CHttpFile* file =NULL;
try{
file = (CHttpFile*)inter_session.OpenURL(url);
}catch(CInternetException * m_pException){
file = NULL;
m_pException->m_dwError;
m_pException->Delete();
inter_session.Close();
return "";
//AfxMessageBox("CInternetException");
}
CString strLine;
if(file != NULL){
while(file->ReadString(strLine) != NULL){
strHtml += strLine;
}
}else{
return "";
//AfxMessageBox("fail");
}
inter_session.Close();
file->Close();
delete file;
file = NULL;
int start = strHtml.Find('"');
int end = strHtml.Find('"', start+1);
//ASSERT( end > start+1 );
if ( ! (end > start+1 && start >0 ))
return "";
CString ret = strHtml.Mid(start+1, end-start-1);
return ret;
}
示例12: mySession
AINIKU_API CString getUrl2(CString url) {
if (url == "") { return ""; }
CInternetSession mySession((LPCTSTR)"aaa", 0);//如果不指定aaa(随便的一个字符串)的话debug模式下会报错
CHttpFile* htmlFile = NULL;
CString str, strHtml;
TRY{
htmlFile = (CHttpFile*)mySession.OpenURL(url);//打开连接
while (htmlFile->ReadString(str)) {
char *pStr = (char*)str.GetBuffer(str.GetLength()); //取得str对象的原始字符串
int nBufferSize = MultiByteToWideChar(CP_UTF8, 0, pStr, -1, NULL, 0); //取得所需缓存的多少
wchar_t *pBuffer = (wchar_t*)malloc(nBufferSize * sizeof(wchar_t));//申请缓存空间
MultiByteToWideChar(CP_UTF8, 0, pStr, -1, pBuffer, nBufferSize*sizeof(wchar_t));//转码
strHtml += pBuffer;
free(pBuffer); //释放缓存
}
return strHtml;
}CATCH(CException, e){
TCHAR err[1024];
e->GetErrorMessage(err, 1024);
return "";
}
示例13: GetHtmlSource
string GetHtmlSource(CString strURL)
{
CInternetSession session;
CHttpFile *file = NULL;
CString strHtml = _T(""); //存放网页数据
file =(CHttpFile*)session.OpenURL(strURL,1,INTERNET_FLAG_RELOAD);
//CString strLine;
char sRecived[1024];
if(file != NULL) {
while(file->ReadString((LPTSTR)sRecived,1024)!=NULL) {
strHtml += sRecived; }
}
session.Close();
if(file!=NULL) file->Close();
delete file; file = NULL;
string html = CT2A(strHtml.GetBuffer(0));
return html;
}
示例14: main
//.........这里部分代码省略.........
// close up the redirected site
pFile->Close();
delete pFile;
pServer->Close();
delete pServer;
if (bProgressMode)
{
cerr << _T("Caution: redirected to ");
cerr << (LPCTSTR) strNewLocation << endl;
}
// figure out what the old place was
if (!AfxParseURL(strNewLocation, dwServiceType, strServerName, strObject, nPort))
{
cerr << _T("Error: the redirected URL could not be parsed.") << endl;
ThrowTearException(2);
}
if (dwServiceType != INTERNET_SERVICE_HTTP)
{
cerr << _T("Error: the redirected URL does not reference a HTTP resource.") << endl;
ThrowTearException(2);
}
// try again at the new location
pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,
strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
pFile->AddRequestHeaders(szHeaders);
pFile->SendRequest();
pFile->QueryInfoStatusCode(dwRet);
if (dwRet != HTTP_STATUS_OK)
{
cerr << _T("Error: Got status code ") << dwRet << endl;
ThrowTearException(2);
}
}
cerr << _T("Status Code is ") << dwRet << endl;
TCHAR sz[1024];
while (pFile->ReadString(sz, 1023))
{
if (bStripMode)
StripTags(sz);
cout << sz;
}
// NOTE: Since HTTP servers normally spit back plain text, the
// above code (which reads line by line) is just fine. However,
// other data sources (eg, FTP servers) might provide binary data
// which should be handled a buffer at a time, like this:
#if 0
while (nRead > 0)
{
sz[nRead] = '\0';
if (bStripMode)
StripTags(sz);
cout << sz;
nRead = pFile->Read(sz, 1023);
}
#endif
pFile->Close();
pServer->Close();
}
catch (CInternetException* pEx)
{
// catch errors from WinINet
TCHAR szErr[1024];
pEx->GetErrorMessage(szErr, 1024);
cerr << _T("Error: (") << pEx->m_dwError << _T(") ");
cerr << szErr << endl;
nRetCode = 2;
pEx->Delete();
}
catch (CTearException* pEx)
{
// catch things wrong with parameters, etc
nRetCode = pEx->m_nErrorCode;
TRACE1("Error: Exiting with CTearException(%d)\n", nRetCode);
pEx->Delete();
}
if (pFile != NULL)
delete pFile;
if (pServer != NULL)
delete pServer;
session.Close();
return nRetCode;
}
示例15: login
DWORD CLoginDlg::login(LPCTSTR serverURL, LPCTSTR requestPage, LPCTSTR formData)
{
#ifdef _HTTPS
CInternetSession session(_T("HelloChat"), INTERNET_FLAG_SECURE);
CHttpConnection* pConnection = session.GetHttpConnection(serverURL, INTERNET_SERVICE_HTTP, INTERNET_DEFAULT_HTTPS_PORT);
CString strHeaders = HEADER;
// OPEN A POST REQUEST
CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, requestPage, NULL, 1, NULL, NULL, INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD |
INTERNET_FLAG_DONT_CACHE |
INTERNET_FLAG_NO_COOKIES);
#else
CInternetSession session(_T("HelloChat"), PRE_CONFIG_INTERNET_ACCESS);
CHttpConnection* pConnection = session.GetHttpConnection(serverURL);
CString strHeaders = HEADER;
// OPEN A POST REQUEST
CHttpFile* pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, requestPage, NULL, 1, NULL, NULL, INTERNET_FLAG_RELOAD |
INTERNET_FLAG_DONT_CACHE |
INTERNET_FLAG_NO_COOKIES);
#endif
// UNICODE
#if defined(_UNICODE)
// Length of form data (including '\\0')
const int dwLength = _tcslen(formData) + 1;
// Alocate ANSI character array
char *lpFormData = new char[dwLength];
// Convert wide char form data to ANSI
//멀티바이트코드로 변환.
VERIFY(0 != ::WideCharToMultiByte(CP_ACP, 0, formData, -1, lpFormData, dwLength, 0, 0));
// Send the request to the HTTP server
VERIFY(pFile->SendRequest(strHeaders, lpFormData, dwLength));
// Delete ANSI array
delete[] lpFormData;
// ANSI
#else
// Send the request to the HTTP server
VERIFY(pFile->SendRequest(strHeaders, (LPVOID)formData, strlen(formData)));
#endif
// GET POST STATUS
DWORD dwPostStatus = 0;
VERIFY(pFile->QueryInfoStatusCode(dwPostStatus));
CString strBuffer = L"";
BOOL brtn = pFile->ReadString(strBuffer);
char* szBuff = LPSTR(LPCTSTR(strBuffer));
if (dwPostStatus == HTTP_STATUS_OK)
{
// 토큰 획득.
BOOL bRtn = getToken(szBuff);
if (!bRtn){
//토큰 획득 실패시.
dwPostStatus = HTTP_STATUS_NO_CONTENT;
//토큰 획득 실패 메시지
CComm func;
func.WriteErrorLog(szBuff);
}
}
else if (dwPostStatus == HTTP_STATUS_DENIED){
//토큰 Expire 확인.
CComm func;
BOOL bRtn = func.isTokenExpire(szBuff);
if (bRtn){
//토큰 만료에 대한 로그 작성
func.WriteErrorLog(szBuff);
// 토큰 Expire 토큰 재발급.
GetPrivateProfileString(L"MYINFO", L"token", L"", (LPWSTR)func.m_myInfo.token, sizeof(func.m_myInfo.token), func.m_strINI);
m_strMyToken = (LPCTSTR)(LPWSTR)func.m_myInfo.token;
DWORD dwRtn = func.TokenRefresh(m_strMyToken);
if (dwRtn == HTTP_STATUS_OK){
//토큰은 다시 재 발급 받았으므로 로그인 다시 시도 메시지.
AfxMessageBox(L"Token Expired\r\nLogin Again");
}
else{
//토큰 재 발급 과정에서 재 발급 실패.
AfxMessageBox(L"Token Refresh Fail.");
}
}
}
pFile->Close();
return dwPostStatus;
}