怎样在vc中访问并显示80端口中的数据,sos 我想用vc对80端口传来的数据进行显示并处理,多谢!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个函数你可能适合,是检查网址是否可以访问的函数int CheckURL(CString strAddress){ CInternetSession session(_T("Check URL")); CHttpConnection *pServer = NULL; CHttpFile *pFile = NULL; CString m_strContent; int nRetValue = 1; m_strContent.Empty(); try { CString strServer; CString strObject; INTERNET_PORT nPort; DWORD dwServiceType; if(!AfxParseURL(strAddress, dwServiceType, strServer, strObject, nPort) || dwServiceType != INTERNET_SERVICE_HTTP) { nRetValue = 0; return nRetValue; } pServer = session.GetHttpConnection(strServer, nPort); pFile = pServer->OpenRequest(1, strObject, NULL, 1, NULL, NULL, INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT); pFile->AddRequestHeaders(_T("Check URL")); pFile->SendRequest(); DWORD dwRet; pFile->QueryInfoStatusCode(dwRet); while(dwRet == HTTP_STATUS_DENIED) { DWORD dwPrompt; dwPrompt = pFile->ErrorDlg(NULL, ERROR_INTERNET_INCORRECT_PASSWORD, FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL); if(dwPrompt != ERROR_INTERNET_FORCE_RETRY) { nRetValue = 0; goto end; } pFile->SendRequest(); pFile->QueryInfoStatusCode(dwRet); } CString strNewLocation; pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation); CString line; while(pFile->ReadString(line)) m_strContent += line + "\r\n"; if((m_strContent.Find("<title>无法找到网页</title>") > 0) || (m_strContent.Find("<title>The page cannot be found</title>") > 0)) { nRetValue = 0; m_strContent.Empty(); } pFile->Close(); pServer->Close(); } catch(CInternetException *pEx) { nRetValue = 0; pEx->Delete(); }end: if(pFile != NULL) { delete pFile; pFile = NULL; } if(pServer != NULL) { delete pServer; pServer = NULL; } session.Close(); return nRetValue;} CSocket socke,secondSocket;CSocket socket.Create(80,SOCK_STREAM);socket.Listen(5);while(true){ socket.Accept(secondSocket); //开线程} 楼上的老兄已经为你写了时刻侦听80 Port的代码最后附加一句:接收信息----〉socket.Receive(&StreamFileInfo,sizeof(SOCKET_STREAM_FILE_INFO));或使用ReceiveFrom()函数 去看一下:http://www.csdn.net/expert/topic/879/879041.xml?temp=.4701807其中可能有你用的 vc中加入空格 在com如何进行运算符重载 超级兔子的打开新窗口父窗口隐藏、关闭子窗口父窗口还原那种效果怎么做? 关于匿名管道阻塞的疑问 一道题,SAP的,弄不明白 一种自定义的图形格式如何在windows的文件管理器里缩略图显示出来 vc怎样设置和数据库关联 应该如何控制鼠标 20,送小分,::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)),Hand 的标志为多少 自问自答 在程序的执行过程中有引用内存0x00000000000,怎么办呢? 大家看看我是不是中病毒了?好奇怪啊!!!!!!
{
CInternetSession session(_T("Check URL"));
CHttpConnection *pServer = NULL;
CHttpFile *pFile = NULL;
CString m_strContent;
int nRetValue = 1; m_strContent.Empty();
try
{
CString strServer;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType; if(!AfxParseURL(strAddress, dwServiceType, strServer, strObject, nPort) || dwServiceType != INTERNET_SERVICE_HTTP)
{
nRetValue = 0;
return nRetValue;
} pServer = session.GetHttpConnection(strServer, nPort); pFile = pServer->OpenRequest(1, strObject, NULL, 1, NULL, NULL, INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT);
pFile->AddRequestHeaders(_T("Check URL"));
pFile->SendRequest(); DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
while(dwRet == HTTP_STATUS_DENIED)
{
DWORD dwPrompt;
dwPrompt = pFile->ErrorDlg(NULL,
ERROR_INTERNET_INCORRECT_PASSWORD,
FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS,
NULL); if(dwPrompt != ERROR_INTERNET_FORCE_RETRY)
{
nRetValue = 0;
goto end;
}
pFile->SendRequest();
pFile->QueryInfoStatusCode(dwRet);
} CString strNewLocation;
pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);
CString line;
while(pFile->ReadString(line))
m_strContent += line + "\r\n"; if((m_strContent.Find("<title>无法找到网页</title>") > 0) || (m_strContent.Find("<title>The page cannot be found</title>") > 0))
{
nRetValue = 0;
m_strContent.Empty();
} pFile->Close();
pServer->Close();
}
catch(CInternetException *pEx)
{
nRetValue = 0;
pEx->Delete();
}end:
if(pFile != NULL)
{
delete pFile;
pFile = NULL;
}
if(pServer != NULL)
{
delete pServer;
pServer = NULL;
}
session.Close();
return nRetValue;
}
CSocket socket.Create(80,SOCK_STREAM);
socket.Listen(5);
while(true){
socket.Accept(secondSocket);
//开线程
}
最后附加一句:接收信息----〉
socket.Receive(&StreamFileInfo,sizeof(SOCKET_STREAM_FILE_INFO));
或使用ReceiveFrom()函数
http://www.csdn.net/expert/topic/879/879041.xml?temp=.4701807
其中可能有你用的