double check your codes, it should works. someone has asked the same question before, but at last it is not related with WinInet.
解决方案 »
- UPD点对点通讯问题?
- 关于cmdshell管道的问题
- 高分抢答:重载MainFrame的WinProc后程序运行响应慢
- CException中使用GetErrorMessage获得错误编号4198630,是什么意思?
- 求《visual c++实现mpeg/jpeg编解码技术》等书电子版
- ICO模式下CListCtrl使用BMP图标的问题,请达人帮忙看看
- 用gd+ bitmap 如何将一张大图存为按比例缩小的一张小图,请高手赐教!
- 在dialogbar里面放cedit,显示不出来??
- 请教一下如下的查询如何改用参数化查询?
- VK_A,VK_B这些键要用,是不是要先声明什么的啊
- 请问:ADO中如何给Parameter的type赋一数组
- 有关AfxBeginThread错误的问题。
but, if i change the original file to another type ,for example, the original file is index.php, and when i change it to the file ,index.html,it works.
I don't know why.
can u give me some tips.
thx.
m_strPath = "/xxxx.php"; xxxx为你要的php文件名
HINTERNET hSession=::InternetOpen("Mozilla 4.0",INTERNET_OPEN_TYPE_PRECONFIG ,
"",INTERNET_INVALID_PORT_NUMBER,0); if(hSession == NULL){
AfxMessageBox("Session Initialization failed!",MB_OK,0);
VERIFY(::InternetCloseHandle(hSession));
return;
} HINTERNET hConnect=::InternetConnect(hSession,//当前internet会话句柄
m_strServer,//server name
INTERNET_INVALID_PORT_NUMBER,
NULL,//"",//user name
"",//password
INTERNET_SERVICE_HTTP,//Type of service to access
0,
0); if(hConnect == NULL){
AfxMessageBox("Connect Initialization failed!",MB_OK,0);
VERIFY(::InternetCloseHandle(hSession));
} LPCTSTR sType = "*/*";
LPCTSTR *pFileType = &sType;
HINTERNET hHttpFile=::HttpOpenRequest(hConnect,
"GET",
m_strPath,
"HTTP/1.1",
NULL,
pFileType,
INTERNET_FLAG_DONT_CACHE,
0); if(hHttpFile == NULL){
AfxMessageBox("HttpFile Initialization failed!",MB_OK,0);
VERIFY(::InternetCloseHandle(hConnect));
VERIFY(::InternetCloseHandle(hSession));
} BOOL bSendRequest = ::HttpSendRequest(hHttpFile,
NULL,
0,
0,
0); if(bSendRequest){
char chQueryBuf[16];
DWORD dwFileSize;
for(int i = 0; i < 16; i++)
chQueryBuf[i] = '\0';
dwFileSize = 0;
DWORD dwQueryBufLen = sizeof(chQueryBuf);
BOOL bQuery = ::HttpQueryInfo(hHttpFile,
HTTP_QUERY_CONTENT_LENGTH,
chQueryBuf,
&dwQueryBufLen,
NULL); if(bQuery){
dwFileSize = (DWORD)atol(chQueryBuf);
}
else{
dwFileSize = 10*1024;
}
char *lpszBuf = new char[dwFileSize + 1]; DWORD dwBytesRead;
BOOL bRead = ::InternetReadFile(hHttpFile,
lpszBuf,
dwFileSize+1,
&dwBytesRead);
char *lpszTemp = lpszBuf;
lpszTemp += dwFileSize;
*lpszTemp = '\0';
lpszTemp = NULL; CFile file;
if(file.Open("d:\\xxxx.php",CFile::modeCreate|CFile::modeWrite))
{
file.Write(lpszBuf,dwBytesRead);
int i;
i = strlen(lpszBuf);
void flush();
file.Close();
}
else
{
MessageBox("dlfj");
}
LPCTSTR *pFileType = &sType;
HINTERNET hHttpFile=::HttpOpenRequest(hConnect, "GET", m_strPath, "HTTP/1.1", NULL, pFileType, INTERNET_FLAG_DONT_CACHE,
0);
关键就是那个文件类型的参数LPCTSTR *lplpszAcceptTypes
我上面的程序是可以下载任意类型文件的,已测试通过