📄 读取信息.txt
字号:
BOOL CBDApp::GetIPAndPort(CString &ip, DWORD &port)
{
BOOL ret=FALSE;
DWORD dwType;
CString strServer;
CString strPath;
INTERNET_PORT dwPort;
AfxParseURL(ServerURL,dwType,strServer,strPath,dwPort);//解析URL
if(dwType==AFX_INET_SERVICE_HTTP)//是以"http://"开头
{
try
{
CInternetSession cis;
CHttpConnection *pHttp;
DWORD dwHttpRequestFlags;
dwHttpRequestFlags=HSR_DOWNLOAD | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT;
cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,5);
pHttp=cis.GetHttpConnection(strServer,dwPort);//连接
CHttpFile *pFile = pHttp->OpenRequest(CHttpConnection::HTTP_VERB_GET,
strPath, NULL, 1, NULL, NULL, dwHttpRequestFlags);
if(pFile->SendRequest())//下载文件
{
CString temp;
if(pFile->ReadString(temp))//读取文件信息,格式为ip:port
{
int m=temp.ReverseFind(':');
if(m>0)
{
CString strIP,strPort;
strIP=temp.Left(m);//根据":"把ip和port分割开来
strPort=temp.Mid(m+1);
ip=strIP;
port=atoi((LPCSTR)strPort);
ret=TRUE;
}
}
}
pFile->Close();
pHttp->Close();
cis.Close();
}
catch(CInternetException* pEx)//出错了就直接跳过,不提示
{
;
}
catch(...)
{
;
}
}
return ret;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -