当您将页面另存为 .xml 或查看页面源代码时,Internet 浏览器的执行方式相同。当然,我的目标是一个以 xml 格式开头的网页:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
我为什么要这样做?好吧,我想将某些网页的整个源转储到一个字符串或 CString 中,我仍然是 figuring out how to do
最佳答案
既然您提到了 Visual C++,那么一个好的解决方案就是利用 Microsoft Research 最近发布的 HTTP Casablanca 库,前提是您也能够使用 C++11。
http://msdn.microsoft.com/en-us/devlabs/casablanca.aspx
您需要使用 HTTP 客户端,类似于本教程中描述的内容, http://msdn.microsoft.com/en-US/devlabs/hh977106.aspx
可以是这样的
http_client client( L"http://somewebsite.com" );
client.request( methods::GET, L"page-to-download.html" )
.then( []( http_response response ) {
cout << "HTML SOURCE:" << endl << response.to_string() << endl; })
.wait();
关于c++ - 如何在 C++ 中从 Internet 下载 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11736170/