1
주식 시세 표시, Google 검색 실행 및 데이터 출력 (현재 가격, 고가, 저가, 변경 비율 등)을 구축하려고합니다. . 부스트 asio 사용하려고하고 서버에서 모든 데이터를 반환하지 않습니다. 부스트 asio를 사용하여 웹 페이지 가져 오기
#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는 상기 응답을 출력하는 문제가되지 않았는지 단지 처음 100 개 문자를 읽으려고하지만 단지 널 문자를 출력한다. Google 페이지 전체를 출력하고 싶습니다. "www.google.com/search?q=$tsla"
어떤 도움을 주시면 감사하겠습니다!
를 인쇄하고 그 결과 프로그램 http://www.boost.org/doc/libs/1_65_1/doc/ : 당신은 플러시를 추가 할 수 있습니다 참고 html/boost_asio/example/cpp03/http/client/sync_client.cpp –
[cURL과 유사한 boost :: asio를 사용하여 HTTP GET 요청 보내기]의 가능한 복제본 (https://stackoverflow.com/questions/28728347/sending-http) -get-request-using-boostasio-like-to-curl) –