0

我试图从雅虎财经网站检索数据。但是使用 cpp-netlib 它不会工作,使用普通浏览器没有问题。

 using namespace boost::network;
 http::client::options options;
 options.follow_redirects(true);

 http::client client(options);

 std::string uri    = "http://finance.yahoo.com/d/quotes.csv?s=ADS.DE&f=n";
 try
    {
     http::client::request request( uri );
     http::client::response response = client.get(request);

     std::string result =body( response );
     std::cout << result << std::endl;
    }
   catch (boost::system::system_error const& e)
    {
     cout << "Warning: could not connect : " << e.what() << std::endl;
    }

我认为问题在于重定向。错误消息如下所示:

<HTML>
<HEAD>
<TITLE>Error</TITLE>
</HEAD>

<BODY BGCOLOR="white" FGCOLOR="black">
<!-- status code : 301 -->
<!-- Error: GET -->
<!-- host machine: yts282.global.media.ir2.yahoo.com -->
<!-- timestamp: 1408186488.000 -->
<!-- url: http://finance.yahoo.com/d/quotes.csv?s=ADS.DE&f=n-->
<H1>Error</H1>
<HR>

解决方案

将请求的网址更改为http://download.finance.yahoo.com/d/quotes.csv?s=ADS.DE&f=n

4

1 回答 1

0

我将请求的网址更改为http://download.finance.yahoo.com/d/quotes.csv?s=ADS.DE&f=n

于 2014-08-17T17:55:08.450 回答