Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7446381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:18:17+00:00 2026-05-29T12:18:17+00:00

I’m just writing a little client side HTTP application. It just sends a GET

  • 0

I’m just writing a little client side HTTP application. It just sends a GET Request to an IP Camera and then receives a Screenshot in jpeg format.

Now for the implementation of HTTP I am using Boost Asio. So for the first try I oriented pretty much at the sync_client example Boost Asio Sync HTTP Client Example.

Now mainly I’m a bit worried by the separation of Headers and Data.

First I get the first line of the response:

boost::asio::streambuf response;
boost::asio::read_until(*m_Socket, response, "\r\n");

std::istream response_stream(&response);
std::string http_version;
response_stream >> http_version;

 if (!response_stream || http_version.substr(0, 5) != "HTTP/")
 {
     std::cout << "Invalid response\n";
     return;
 }

uint32_t status_code;
response_stream >> status_code;
std::string status_message;
std::getline(response_stream, status_message);  

 if (status_code != 200)    // 200 = status code OK
 {
     std::cout << "Response returned with status code " << status_code << "\n";
     return;
 }

Now until here everything is clear to me.I’m reading until first new line and then check the stuff in my buffer.

Now I’m trying to read the second part of the header:

 boost::asio::read_until(*m_Socket, response, "\r\n\r\n");

 std::string header;
 while (std::getline(response_stream, header) && (header != "\r"))
 {
      std::cout << header << "\n";
 }
 std::cout << "\n";

Now to this I have some questions:

  1. The while loop is searching until there is a blank line ( the only line where a \r stands all by itself ). Now if I assume that a new line is defined by \r , why do I use \r\n\r\n at boost::asio::read_until ? I mean I would expect wether the one or the other, but both?

  2. If I call the boost::asio::read_until method with \r\r as delimiter it throws an End of File exception. This stands in contrary to what my while loop is searching since this is looking for a \r\r ( since it looks line after line, and every line closes with a \r )

So as you can see Im quite worried how to divide stuff inside my header. It’s getting even worser because the boost::asio::read_until call does always read further than the delmiter ( this is actually OK, since it’s mentioned in the documentation ), but still it kinda always has the same trail of data ( from the actualy jpeg ), with the same length following.

Maybe someone could enlighten me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:18:18+00:00Added an answer on May 29, 2026 at 12:18 pm

    ‘\r’ is the carriage return (CR) character and ‘\n’ is the line-feed (LF) character. HTTP message lines are terminated by “\r\n” (CRLF).

    From “HTTP The Definitive Guide”:

    It is worth pointing out that while the HTTP specification for
    terminating lines is CRLF, robust application also should accept just
    a line-feed character. Some older or broken HTTP applications do not
    always send both the carriage return and line feed.

    What seems to be throwing you off is that some line I/O functions (in this case std::getline()) automatically strip the trailing ‘\n’ so you are only seeing the preceding ‘\r’. I think what you should be doing, is looking for a blank line (rather than a line with only ‘\r’). And a line that is only ‘\r’ should be considered a blank line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.