I'm trying to build a program that would take in a stock ticker, run a google search for it, and output data (current price, high, low, percent change, etc.). I am trying to use boost asio and it is not returning any data from the server.
#include "stdafx.h"
#include <iostream>
#include <istream>
#include <ostream>
#include <string>
#include <boost/asio.hpp>
std::string getStockPage(std::string ticker) {
boost::asio::ip::tcp::iostream stream;
stream.connect("www.google.com", "http");
std::cout << "connected\n";
stream << "GET /search?q=" << ticker << " HTTP/1.1\r\n";
stream << "Host: www.google.com\r\n";
stream << "Cache-Control: no-cache\r\n";
//stream << "Content-Type: application/x-www-form-urlencoded\r\n\r\n";
stream << "Connection: close\r\n\r\n";
std::cout << "sent\n";
std::ostringstream os;
//os << stream.rdbuf();
char buffer[100];
os << stream.readsome(buffer, 100);
return std::string(buffer, 100);
}
int main() {
std::cout << getStockPage("$tsla");
std::cout << "done\n";
std::string temp;
std::getline(std::cin, temp);
return 0;
}
I tried to read just the first 100 characters to see if it was having issues outputting the response, but it only outputs null characters. I want it to output the entirety of the google page "www.google.com/search?q=$tsla"
Any help would be greatly appreciated!