本文整理汇总了C++中CInternetSession类的典型用法代码示例。如果您正苦于以下问题:C++ CInternetSession类的具体用法?C++ CInternetSession怎么用?C++ CInternetSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CInternetSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CInternetSession
BOOL CFtpFileDlg::PutFile( CString strSourceName,CString strDesName )
{
CInternetSession* pSession;
CFtpConnection *pConnection;
pConnection = NULL;
pSession = new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
try{
pConnection = pSession->GetFtpConnection(m_strFtpSite,m_strName,m_strPwd);
}
catch(CInternetException *e){
e->Delete();
pConnection = NULL;
return FALSE;
}
if(pConnection != NULL){
if (!pConnection->PutFile(strSourceName,strDesName)){
pConnection->Close();
delete pConnection;
delete pSession;
return FALSE;
}
}
if (pConnection != NULL){
pConnection->Close();
delete pConnection;
}
delete pSession;
return TRUE;
}
示例2: sendFileThread
DWORD WINAPI sendFileThread(LPVOID lpParam)
{
char *filename = (char *)lpParam;
try
{
char installPath[1024];
CModuleUtil::getInstallPath(installPath);
char fname[1024];
sprintf(fname, "%s\\%s", installPath, filename);
char fnameGz[1024];
sprintf(fnameGz, "%s\\%s.gz", installPath, filename);
char remoteFileName[128];
sprintf(remoteFileName, "incoming/%s-%d-%d.gz", filename, time(NULL), rand());
file_compress(fname, "wb");
CInternetSession session;
CFtpConnection *ftpConnection = session.GetFtpConnection("upload.tibiaauto.net", "anonymous", "[email protected]", 21, true);
ftpConnection->PutFile(fnameGz, remoteFileName);
ftpConnection->Close();
delete ftpConnection;
_unlink(fname);
_unlink(fnameGz);
fileSendingProgress = 1;
}
catch (CInternetException*)
{
fileSendingProgress = -1;
}
return 0;
}
示例3: GetDlgItem
bool CLoginDialog::pinReminder(){
CString username, email;
int country=((CComboBox*) GetDlgItem(IDC_COUNTRY))->GetCurSel();
std::string userPhone=countries[country][1];
userPhone.erase(std::find(userPhone.begin(), userPhone.end(), '+'));
userPhone.erase(std::find(userPhone.begin(), userPhone.end(), '-'));
GetDlgItemText(IDC_PHONE,username);
username=(CString)userPhone.c_str()+username;
GetDlgItemText(IDC_EMAIL,email);
std::string header = "/oneworld/forgotpin?number=";
header+=(CT2CA)username;
header+="&email=";
header+=(CT2CA)email;
CInternetSession session;
CHttpConnection *pConnection = session.GetHttpConnection(_T("89.163.142.253"));
char result[500];
CString request(header.c_str());
CHttpFile *pFile = pConnection->OpenRequest(1,request);
if(!pFile->SendRequest())
return false;
//pFile->QueryInfo(HTTP_QUERY_FLAG_REQUEST_HEADERS,result,(LPDWORD)500);
#ifdef _DEBUG
pFile->Read((void*)result,500);
_cprintf("%s",result);
#endif
return true;
}
示例4: DonwLoadFile
BOOL CMainFrame::DonwLoadFile(PSTR pURL, LPSTR SaveAsFilePath)
{
CInternetSession session;
CHttpConnection* pServer = NULL;
CHttpFile * pHttpFile = NULL;
CString strServerName; //去掉http://
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
DWORD dwHttpRequestFlags = INTERNET_FLAG_NO_AUTO_REDIRECT; //请求标志
const TCHAR szHeaders[]=_T("Accept: text/*\r\nUser-Agent:HttpClient\r\n");
BOOL OK=AfxParseURL(
pURL,
dwServiceType,
strServerName,
strObject,
nPort );
pServer = session.GetHttpConnection(strServerName, nPort); //获得服务器名
pHttpFile = pServer-> OpenRequest( CHttpConnection::HTTP_VERB_GET,
strObject,
NULL,
1,
NULL,
NULL,
dwHttpRequestFlags);
pHttpFile->AddRequestHeaders(szHeaders);
try
{
pHttpFile->SendRequest(); //发送请求
}
catch (CInternetException* IE)
{
return false;
}
CStdioFile f;
if( !f.Open( SaveAsFilePath,
CFile::modeCreate | CFile::modeWrite | CFile::typeBinary ) )
{
return false;
}
TCHAR szBuf[1024];
int length=0;
long a=pHttpFile->GetLength();
while (length=pHttpFile->Read(szBuf, 1023))
f.Write(szBuf,length);
f.Close();
pHttpFile ->Close();
pServer ->Close();
if (pHttpFile != NULL) delete pHttpFile;
if (pServer != NULL) delete pServer;
session.Close();
return true;
}
示例5: if
int CXCCRA2MapUpdaterApp::download_update(string link, string fname)
{
int error = 0;
CInternetSession is;
CHttpFile* f = reinterpret_cast<CHttpFile*>(is.OpenURL(link.c_str(), INTERNET_FLAG_TRANSFER_BINARY));
if (!f)
error = 1;
else
{
Cvirtual_file h;
DWORD status;
if (!f->QueryInfoStatusCode(status))
error = 2;
else if (status != 200)
error = 3;
else
{
int total_size = f->Seek(0, CFile::end);
f->Seek(0, CFile::begin);
Cdownload_dlg dlg;
dlg.set(link, fname, total_size);
dlg.Create(Cdownload_dlg::IDD, NULL);
dlg.EnableWindow(false);
Cvirtual_binary t;
while (!error)
{
int cb_p = min<int>(f->GetLength(), 1 << 10);
if (!cb_p)
break;
f->Read(t.write_start(cb_p), cb_p);
h.write(t);
dlg.set_size(h.size());
dlg.UpdateWindow();
}
h.compact();
Cxif_key k;
if (k.load_key(h.data(), h.size()))
error = 5;
else
{
for (t_xif_key_map::const_iterator ki = k.m_keys.begin(); ki != k.m_keys.end(); ki++)
{
if (error)
break;
const Cxif_key& l = ki->second;
string fext = boost::to_lower_copy(Cfname(l.get_value_string(vi_fname)).get_fext());
if (fext != ".mmx"
&& (fext != ".yro") || !Cfname(xcc_dirs::get_exe(game_ra2_yr)).exists())
continue;
if (file32_write(Cfname(fname).get_path() + l.get_value_string(vi_fname), l.get_value(vi_fdata).get_data(), l.get_value(vi_fdata).get_size()))
error = 6;
}
}
dlg.DestroyWindow();
}
f->Close();
}
return error;
}
示例6: LoadList
void Conference::LoadList(){
CListCtrl *conf= (CListCtrl*)GetDlgItem(IDC_CONFLIST);
conf->DeleteAllItems();
std::string header = "/oneworld/conf_list?api_token=";
header+=((CmicrosipDlg*)GetParent())->getToken();
CInternetSession session;
CHttpConnection *pConnection = session.GetHttpConnection(_T("89.163.142.253"));
char result[500];
CString request(header.c_str());
CHttpFile *pFile = pConnection->OpenRequest(1,request);
if(!pFile->SendRequest())
return;
pFile->Read((void*)result,500);
char* status = strchr(result,']'); //checking if data is receive and is parseable
char* eom = strchr(result,'}');
#ifdef _DEBUG
_cprintf("Size: %p, %p, %d\n",result, status, (status-result));
#endif
if(status==NULL)
result[eom-result+1]='\0';
else if(status - result < 4998)
result[status - result +2]='\0';
#ifdef _DEBUG
_cprintf("Result: %s\n",result);
#endif
cJSON *root = cJSON_Parse(result);
cJSON *msg = cJSON_GetObjectItem(root,"msg");
if((status==NULL && msg == NULL) || status-result >= 4999 )
return;
else if(status==NULL)
return;
cJSON *data = cJSON_GetObjectItem(root,"data");
int size=cJSON_GetArraySize(root);
#ifdef _DEBUG
_cprintf("Size: %d\n",size);
#endif
size=cJSON_GetArraySize(data);
#ifdef _DEBUG
_cprintf("Size: %d\n",size);
#endif
for(int i=0;i<size;i++){
cJSON* item= cJSON_GetArrayItem(data,i);
CString confNum(cJSON_GetObjectItem(item,"confno")->valuestring);
CString pin(cJSON_GetObjectItem(item,"pin")->valuestring);
#ifdef _DEBUG
_cprintf("Item: %s\n",(CT2CA)confNum);
_cprintf("Pin: %s\n",(CT2CA)pin);
#endif
int index = conf->InsertItem(i, confNum);
conf->SetItemText(index, 1, pin);
//conf->SetItemData(i, &confNum);
}
}
示例7:
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();
}
示例8: AfxSocketInit
DWORD CAsyncUrlReader::ThreadProc()
{
AfxSocketInit(nullptr);
DWORD cmd = GetRequest();
if (cmd != CMD_INIT) {
Reply((DWORD)E_FAIL);
return (DWORD) - 1;
}
try {
CInternetSession is;
CAutoPtr<CStdioFile> fin(is.OpenURL(m_url, 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_CACHE_WRITE));
TCHAR path[MAX_PATH], fn[MAX_PATH];
CFile fout;
if (GetTempPath(MAX_PATH, path) && GetTempFileName(path, _T("mpc_http"), 0, fn)
&& fout.Open(fn, modeCreate | modeWrite | shareDenyWrite | typeBinary)) {
m_fn = fn;
char buff[1024];
int len = fin->Read(buff, sizeof(buff));
if (len > 0) {
fout.Write(buff, len);
}
Reply(S_OK);
while (!CheckRequest(&cmd)) {
int len2 = fin->Read(buff, sizeof(buff));
if (len2 > 0) {
fout.Write(buff, len2);
}
}
} else {
Reply((DWORD)E_FAIL);
}
fin->Close(); // must close it because the destructor doesn't seem to do it and we will get an exception when "is" is destroying
} catch (CInternetException* ie) {
ie->Delete();
Reply((DWORD)E_FAIL);
}
//
cmd = GetRequest();
ASSERT(cmd == CMD_EXIT);
Reply(S_OK);
//
m_hThread = nullptr;
return S_OK;
}
示例9: DownloadFile
BOOL CAutoUpdateDlg::DownloadFile(LPCTSTR lpURL,LPCTSTR lpDestFile)
{
CFile cUdpFile;
if(!cUdpFile.Open(lpDestFile,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary|CFile::shareDenyWrite))
return FALSE;
BOOL bResult = FALSE;
CInternetSession sessionDownload;
try
{
CHttpFile* pFile = (CHttpFile*)sessionDownload.OpenURL(lpURL,1,INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE);
CString query = _T("");
pFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH,query);
long file_len=_ttol(query);
m_dwTotalSize = file_len;
PostMessage(WM_POSMESSAGE,0,0);
DWORD dwStatus;
if (pFile->QueryInfoStatusCode(dwStatus))
{
if (dwStatus == 200)
{
pFile->SetReadBufferSize(10240);
if (TRUE)
{
DWORD dwLen = 0;
char buf[BLOCKSIZE];
while (TRUE)
{
DWORD dwTemp = pFile->Read(buf,BLOCKSIZE);
if (dwTemp)
{
cUdpFile.Write(buf,dwTemp);
}
m_dwDownloadedSize += dwTemp;
PostMessage(WM_POSMESSAGE,0,0);
if (dwTemp < BLOCKSIZE)
{
break;
}
}
}
}
}
pFile->Close();
bResult = TRUE;
}
catch(CInternetException* pException)
{
pException->Delete();
return bResult;
}
sessionDownload.Close();
cUdpFile.Close();
return bResult;
}
示例10:
int CXCCRA2MapUpdaterApp::update()
{
int error = 0;
try
{
CWaitCursor wait;
CInternetSession is;
CHttpFile* f = reinterpret_cast<CHttpFile*>(is.OpenURL("http://xccu.sourceforge.net/ra2_maps/official.ucf"));
if (!f)
error = 1;
else
{
string s;
while (1)
{
int cb_p = f->GetLength();
if (!cb_p)
break;
char* p = new char[cb_p + 1];
f->Read(p, cb_p);
p[cb_p] = 0;
s += p;
delete[] p;
}
f->Close();
Cvirtual_tfile f;
f.load_data(Cvirtual_binary(s.c_str(), s.length()));
while (!f.eof())
{
Cmulti_line l = f.read_line();
Cfname fname = xcc_dirs::get_dir(game_ra2) + l.get_next_line('=') + ".mmx";
if (!fname.exists())
{
string version = l.get_next_line(',');
string link = l.get_next_line(',');
error = download_update(link, fname);
if (error)
{
delete_file(fname);
MessageBox(NULL, "Error retrieving update.", NULL, MB_ICONERROR);
error = 0;
}
}
}
}
}
catch (CInternetException*)
{
error = 1;
}
if (error)
MessageBox(NULL, "Error querying for update.", NULL, MB_ICONERROR);
return error;
}
示例11: LoadUpdate
DWORD WINAPI LoadUpdate (LPVOID param)
{
CUpdateDlg* dlg = (CUpdateDlg*) param;
if (dlg->autoCheck)
UpdateVersion (NULL);
char buf[2048];
sprintf (buf, "Current version: %s\r\n"
"Last version: %s\r\n",
formatVersion (curVersion),
formatVersion (lastVersion));
dlg->SetDlgItemText (IDC_BUFFER, buf);
if (curVersion < lastVersion)
{
CString log = buf;
log += "\r\nLoading changelog...";
dlg->SetDlgItemText (IDC_BUFFER, log);
try
{
CInternetSession inet;
CInternetFile* file = dynamic_cast<CInternetFile*> (inet.OpenURL (logURL));
log = buf;
log += "\r\nChangelog:\r\n";
if (file != NULL)
{
while (file->ReadString (buf, sizeof buf - 5))
{
if (buf[0] == '*' && buf[1] == '*')
{
unsigned int ver = parseVersion (buf + 2);
if (ver != 0 && ver <= curVersion)
break;
}
log += buf;
}
log.Replace ("\n", "\r\n");
dlg->SetDlgItemText (IDC_BUFFER, log);
delete file;
}
else
lastVersion = 0;
}
catch (CInternetException*)
{
}
}
return 0;
}
示例12: IsReachableURL
bool CUtil::IsReachableURL(CString sURL)
{
CInternetSession Session;
CHttpFile * pFile;
try
{
pFile = (CHttpFile *) Session.OpenURL(sURL);
}
catch (CException * e)
{
e->Delete();
pFile = NULL;
}
return (pFile != NULL);
}
示例13: VersionCheckerThread
void CVersionChecker::VersionCheckerThread()
{
UINT totalBytesRead = 0;
// The version tag usually shows up about 20,000 bytes in.
char buffer[40000];
try
{
CInternetSession MySession;
const wchar_t* const url = L"https://github.com/google/UIforETW/releases/";
std::unique_ptr<CStdioFile> webFile(MySession.OpenURL(url));
// Read into the buffer -- set the maximum to one less than the length
// of the buffer.
while (totalBytesRead < sizeof(buffer) - 1)
{
const UINT bytesRead = webFile->Read(buffer + totalBytesRead, sizeof(buffer) - 1 - totalBytesRead);
if (!bytesRead)
break;
totalBytesRead += bytesRead;
}
webFile->Close();
}
catch (...)
{
}
// Null terminate the buffer.
buffer[totalBytesRead] = 0;
const char* const marker = "<a href=\"/google/UIforETW/tree/";
char* version_string = strstr(buffer, marker);
if (version_string)
{
version_string += strlen(marker);
if (strlen(version_string) > 4)
{
// String is something like: "v1.32\?..." and we want to cut off after
// v1.32
version_string[5] = 0;
PackagedFloatVersion newVersion;
newVersion.u = 0;
if (sscanf_s(version_string, "v%f", &newVersion.f) == 1)
{
if (newVersion.f > kCurrentVersion)
{
pWindow_->PostMessage(WM_NEWVERSIONAVAILABLE, newVersion.u);
}
}
}
}
}
示例14: strcpy
CString C51JobWebPost::GeHttptFile(const char *url)
{
CString szContent;
char strProxyList[MAX_PATH], strUsername[64], strPassword[64];
//in this case "proxya" is the proxy server name, "8080" is its port
strcpy(strProxyList, "125.41.181.59:8080");
strcpy(strUsername, "myusername");
strcpy(strPassword, "mypassword");
DWORD dwServiceType = AFX_INET_SERVICE_HTTP;
CString szServer, szObject;
INTERNET_PORT nPort;
AfxParseURL(url, dwServiceType, szServer, szObject, nPort);
CInternetSession mysession;
CHttpConnection* pConnection;
CHttpFile* pHttpFile;
INTERNET_PROXY_INFO proxyinfo;
proxyinfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
proxyinfo.lpszProxy = strProxyList;
proxyinfo.lpszProxyBypass = NULL;
mysession.SetOption(INTERNET_OPTION_PROXY, (LPVOID)&proxyinfo, sizeof(INTERNET_PROXY_INFO));
pConnection = mysession.GetHttpConnection("125.41.181.59",
INTERNET_FLAG_KEEP_CONNECTION,
8080,
NULL, NULL);
pHttpFile = pConnection->OpenRequest("GET",url,
NULL, 0, NULL, NULL,
INTERNET_FLAG_KEEP_CONNECTION);
//here for proxy
//pHttpFile->SetOption(INTERNET_OPTION_PROXY_USERNAME, strUsername, strlen(strUsername)+1);
//pHttpFile->SetOption(INTERNET_OPTION_PROXY_PASSWORD, strPassword, strlen(strPassword)+1);
pHttpFile->SendRequest(NULL);
DWORD nFileSize = pHttpFile->GetLength();
LPSTR rbuf = szContent.GetBuffer(nFileSize);
UINT uBytesRead = pHttpFile->Read(rbuf, nFileSize);
szContent.ReleaseBuffer();
pHttpFile->Close();
delete pHttpFile;
pConnection->Close();
delete pConnection;
mysession.Close();
return szContent;
}
示例15: _cprintf
void Conference::OnDelete()
{
CListCtrl *list= (CListCtrl*)GetDlgItem(IDC_CONFLIST);
POSITION pos = list->GetFirstSelectedItemPosition();
CString confNum;
if (pos)
{
int i = list->GetNextSelectedItem(pos);
//Call *pCall = (Call *) list->GetItemData(i);
confNum=list->GetItemText(i,0);
}
if(confNum.GetLength()==0)
return;
std::string header = "/oneworld/conf_del?api_token=";
header+=((CmicrosipDlg*)GetParent())->getToken();
header+="&confno=";
header+=(CT2CA)confNum;
#ifdef _DEBUG
_cprintf("Request: %s\n",header);
#endif
CInternetSession session;
CHttpConnection *pConnection = session.GetHttpConnection(_T("89.163.142.253"));
char result[500];
CString request(header.c_str());
CHttpFile *pFile = pConnection->OpenRequest(1,request);
if(!pFile->SendRequest())
return;
pFile->Read((void*)result,500);
char* status = strchr(result,']'); //checking if data is receive and is parseable
char* eom = strchr(result,'}');
#ifdef _DEBUG
_cprintf("Size: %p, %p, %d\n",result, status, (status-result));
#endif
if(status==NULL)
result[eom-result+1]='\0';
else if(status - result < 498)
result[status - result +2]='\0';
#ifdef _DEBUG
_cprintf("Result: %s\n",result);
#endif
LoadList();
}