Why the web client doesn't connect to Https?

Learn Boost::Asio.

Took the basic example from the Boost lists the contents of the website in the console everything works, but if the site is Https it throws a 302 error :(
I will appreciate any tips!

int main()
 setlocale(LC_ALL, "Russian");
 char* argv[3];

 argv[0] = "sync_client";
 argv[1] = "yandex.ru";
 argv[2] = "";

 boost::asio::io_service io_service;

 Formation of endpoints
 tcp::resolver resolver(io_service);
 tcp::resolver::query query(argv[1], "80");
 tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);

 //Create socket and connect to the address
 tcp::socket socket(io_service);
 boost::asio::connect(socket, endpoint_iterator);

 //Forming request headers
 boost::asio::streambuf request;
 std::ostream request_stream(&request);
 request_stream << "GET" << argv[2] << "HTTP/1.1\r\n";
 request_stream << "Host:" << argv[1] << "\r\n";
 request_stream << "User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:49.0) Gecko/20100101 Firefox/49.0";
 request_stream << "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
 request_stream << "Accept-Language: ru-ru,ru;q=0.8,en-US;q=0.5,en;q=0.3";
 request_stream << "Accept-Encoding: gzip, deflate, br";
 request_stream << "Connection: keep-alive\r\n\r\n";

 //Songranny the entry in the flow
 boost::asio::write(socket, request);

 //Read the stream until the delimiter "\r\n"
 boost::asio::streambuf response;
 boost::asio::read_until(socket, response, "\r\n");

 std::istream response_stream(&response);
 std::string http_version;
 response_stream >> http_version;
 unsigned int status_code;
 response_stream >> status_code;
 std::string status_message;
 std::getline(response_stream, status_message);
 if (!response_stream || http_version.substr(0, 5) != "HTTP/")
 std::cout << "Invalid response\n";
 //return 1;
 if (status_code != 200)
 std::cout << "Response returned with status code" << status_code << "\n";
 //return 1;

 //Read the stream until the delimiter "\r\n\r\n"
 boost::asio::read_until(socket, response, "\r\n\r\n");

 //Display the server response headers
 std::string header;
 while (std::getline(response_stream, header) && header != "\r")
 std::cout << header << "\n";

 boost::system::error_code error;

 //Display the response body the server
 while (boost::asio::read(socket, response, boost::asio::transfer_at_least(1), error))
 std::cout << &response;

 if (error != boost::asio::error::eof)
 throw boost::system::system_error(error);
 catch (std::exception& e)
 std::cout << "Exception:" << e.what() << "\n";


 return 0;
July 2nd 19 at 17:10
1 answer
July 2nd 19 at 17:12
This is not a bug, just a website redirects you to the HTTPS version. Some sites do not work over HTTP, including HTTPS by force thus
Maybe, but how do I get a normal response from the server? What to change in code? not for the first hour already I bet :( - Chadd_Hane commented on July 2nd 19 at 17:15
to yandex.ru/help connected, because there http why https is not digested? - Chadd_Hane commented on July 2nd 19 at 17:18
Than the 302 response crazy? He sees your useragent, sees that the browser must support HTTPS, and redirects you back with a 302 response. Try to pretend to be some kind of Lynx - turner.Beahan commented on July 2nd 19 at 17:21
: Well, the titles I come, no body. And Http is the body. Change the Protocol from 80 to 443, emits code 400. Maybe the fact that my home-made "browser" does not support Https? Thanks that responded) - Chadd_Hane commented on July 2nd 19 at 17:24
There is no body, because the 302 response redirect to HTTPS.
Of course your hand doesn't support HTTPS, because when you try unencrypted HTTP request to port 443 gets error 400 - turner.Beahan commented on July 2nd 19 at 17:27
: So the problem is clear. The real question is how to do to support it? - Chadd_Hane commented on July 2nd 19 at 17:30
Tie SSL will have to. But from Google's example of how to do the request through HTTPS

more cumbersome official example from boost
www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/... - turner.Beahan commented on July 2nd 19 at 17:33
: Oh, thank you! As I am in bust such an example is not found - Chadd_Hane commented on July 2nd 19 at 17:36

Find more questions by tags ParsingHTTPSBoostC++