Search code examples
c++boostyahoo-financecpp-netlib

cpp-netlib fetch Yahoo-Finance content failed after redirect


i tried to retrieve data from the yahoo finance website. But with the cpp-netlib it wont work, with a normal Browser there is no problem.

 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;
    }

I think the problem is the redirection. The error message looks like:

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

SOLUTION

changed the requested url to http://download.finance.yahoo.com/d/quotes.csv?s=ADS.DE&f=n


Solution

  • I changed the requested url to http://download.finance.yahoo.com/d/quotes.csv?s=ADS.DE&f=n