Boost logo

Boost Users :

Subject: Re: [Boost-users] asio problem with detecting http header end
From: Igor R (boost.lists_at_[hidden])
Date: 2011-07-30 14:39:05


> I use Boost.ASIO for receiving Twitter JSON data. I use this code:
> boost::asio::write( p_socket, l_request );
>
> boost::asio::streambuf l_response;
>
> boost::asio::read_until(p_socket, l_response, "\r\n\r\n");
> So in my optional the l_response variable should be read the full HTTP
> header. But if I write it to the std::cout I get:
> HTTP/1.1 200 OK
> Date: Fri, 29 Jul 2011 20:08:37 GMT
> Server: hi
> Cache-Control: max-age=15, must-revalidate, max-age=300
> Expires: Fri, 29 Jul 2011 20:13:37 GMT
> Content-Type: application/json;charset=utf-8
> Content-Length: 9763
> Vary: Accept-Encoding
> X-Varnish: 1045274856
> Age: 0
> Via: 1.1 varnish
> X-Cache-Svr: smf1-aba-35-sr2.prod.twitter.com
> X-Cache: MISS
> Connection: close
> {"completed_in":0.025,"max_id":97033383951081472,"max_id_str":"97033383951081472","next_page":"?page=2&max_id=9703338395108147
> I can change the "until read parameter" to \n, Connection: close or
> something else, but the read_until method does not stop the reading at the correct chars.

Read the manual:
http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/reference/read_until/overload3.html

read_until is just a convenience function that reads *some* data until
it finds your substring.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net