关于Win32访问http的问题
void net()
{
DWORD waep;
CString aa;
HINTERNET internet = InternetOpen(L"http://www.baidu.com", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL);
if (!internet)
{
AfxMessageBox(CString("InternetOpen Failed!"));
return;
}
HINTERNET file_handle = InternetOpenUrl(internet, _T("http://www.baidu.com"), NULL, 0, INTERNET_FLAG_RELOAD, 0);
waep=GetLastError();
aa.Format(_T("%d"),waep);
if (!file_handle)
{
MessageBox(NULL,aa,L"error",NULL);
AfxMessageBox(CString("InternetOpenUrl Failed!"));
return;
}
//从url地址中读取文件内容到缓冲区buffer
char buffer[512];//下载文件的缓冲区
DWORD bytes_read;//下载的字节数
BOOL b = InternetReadFile(file_handle, buffer, 512, &bytes_read);
if(!b)
{
AfxMessageBox(CString("InternetReadFile Failed!"));
return;
}
wchar_t wBuffer[512];
wmemset(wBuffer, 0, 512);
MultiByteToWideChar(CP_ACP, 0, buffer, 512, wBuffer, 512);
AfxMessageBox(wBuffer);
// 关闭连接
InternetCloseHandle(internet);
}
为什么我用这个程序总是连接失败呢,返回error 12029 哪个高手帮我看看是出了什么问题,我用模拟器上网没有问题。本人太穷了就给20分,大家见谅啦