如何从C ++的互联网下载xml [英] How do I download xml from the internet in C++

查看:159
本文介绍了如何从C ++的互联网下载xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您将网页另存为.xml或查看网页来源时,与浏览器做同样的事情。当然,我的目标是使用xml的网页,并且像这样开始:

 <?xml version =1.0编码= UTF-8 >?; 
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional。 DTD>

为什么我要这么做?那么我想将某些网页的整个源代码转储为字符串或CString,我仍然是搞清楚如何做 既然你提到了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客户端(L HTTP:// somewebs ite.com); 

client.request(methods :: GET,Lpage-to-download.html)
.then([](http_response response){
cout<<< ;HTML SOURCE:<< endl<<< response.to_string()<< endl;})
.wait();


The same way an internet browser does it when you save page as .xml, or view page source. Of course I am targeting a webpage that is in xml and starts like this:

<?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">

Why do I want to do this? Well I want to dump the entire source of certain webpages into a string or CString, which I'm still figuring out how to do

解决方案

Since you mentioned Visual C++, a good solution would be to make use of the recently published HTTP Casablanca library from Microsoft Research, provided you are able to use C++11 as well.

http://msdn.microsoft.com/en-us/devlabs/casablanca.aspx

The you need to make use of a HTTP client, similar to what is described in this tutorial, http://msdn.microsoft.com/en-US/devlabs/hh977106.aspx

Which can be something like,

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 ++的互联网下载xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆