关于Win32访问http的问题

txwdyyy001 2009-12-25 10:27:47
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分,大家见谅啦
...全文
82 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
txwdyyy001 2009-12-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 infsafe 的回复:]
解决了赶紧给分啊....嘿嘿
[/Quote]

哈哈。够心急的!
infsafe 2009-12-25
  • 打赏
  • 举报
回复
INTERNET_OPEN_TYPE_DIRECT
Resolves all host names locally.
在本地解析所有的主机名.

INTERNET_OPEN_TYPE_PRECONFIG
Retrieves the proxy or direct configuration from the registry.
检索代理或直接从注册表中配置

ERROR_INTERNET_CANNOT_CONNECT
Error: (12029)
A connection with the Server could Not Be Established
不能完成建立到服务器的链接.

很明显, 检索到的代理不对, 或者注册表中的配置不对.
直接解析就正确了.


txwdyyy001 2009-12-25
  • 打赏
  • 举报
回复
我把InternetOpen中的INTERNET_OPEN_TYPE_PRECONFIG改成INTERNET_OPEN_TYPE_DIRECT就可以连接成功了。但是不知道原理
infsafe 2009-12-25
  • 打赏
  • 举报
回复
解决了赶紧给分啊....嘿嘿
txwdyyy001 2009-12-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 infsafe 的回复:]
INTERNET_OPEN_TYPE_DIRECT
Resolves all host names locally.
在本地解析所有的主机名.

INTERNET_OPEN_TYPE_PRECONFIG
Retrieves the proxy or direct configuration from the registry.
检索代理或直接从注册表中配置

ERROR_INTERNET_CANNOT_CONNECT
Error: (12029)
A connection with the Server could Not Be Established
不能完成建立到服务器的链接.

很明显, 检索到的代理不对, 或者注册表中的配置不对.
直接解析就正确了.



[/Quote]

解释的真好啊。

7,657

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧