18,356
社区成员
发帖
与我相关
我的任务
分享
CInternetSession session("sess",0);
CHttpConnection* connect = session.GetHttpConnection(
sURL
,INTERNET_FLAG_NO_AUTO_REDIRECT
,80,"Rainny","Rainny");
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
if (!AfxParseURL(sURL, dwServiceType, strServerName, strObject, nPort) ||
dwServiceType != INTERNET_SERVICE_HTTP)
{
AfxMessageBox("AfxParseURL Error");
return;
}
CHttpFile* outfile;
outfile = connect->OpenRequest(CHttpConnection::HTTP_VERB_GET,strObject,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
//pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
DWORD dwStatus;
DWORD dwBuffLen = sizeof(dwStatus);
BOOL bSuccess = outfile->QueryInfo(
HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,
&dwStatus, &dwBuffLen);
if( bSuccess && dwStatus >= 200 && dwStatus < 300)//根据HTTP协议,如果存在此文件并且一切正常,返回值就会在200-300之间。
{
char buffer[2048 + 1];
memset(buffer, 0, 2049);
int nReadCount = 0;
while((nReadCount = outfile->Read(buffer, 2048)) > 0)
{//每次读2048个字节,一直读,直到没数据。
buffer[nReadCount] = '\0';
//strSentence += buffer;
memset(buffer, 0, 2049);
}
}