title: How to read image content from an HTTP server response using Poco C++?
body: <p>I am writing an HTTP client in C++ with Poco and there is a situation in which the server sends a response with a jpeg image content (in bytes). I need the client to process the response and generate a jpg image file from those bytes.</p>
  
  <p>I searched the Poco library for appropriate functions but I haven't found any. It seems that the only way to do it is manually.</p>
  
  <p>This is part of my code. It takes the response and makes the input stream start at the beginning of the image content.</p>
  
  <pre><code>    /* Get response */
      HTTPResponse res;
      cout &lt;&lt; res.getStatus() &lt;&lt; " " &lt;&lt; res.getReason() &lt;&lt; endl;
  
      istream &amp;is = session.receiveResponse(res);
  
      /* Download the image from the server */
      char *s = NULL;
      int length;
      std::string slength;
  
      for (;;) {
          is.getline(s, '\n');
          string line(s);
  
          if (line.find("Content-Length:") &lt; 0)
              continue;
  
          slength = line.substr(15);
          slength = trim(slength);
          stringstream(slength) &gt;&gt; length;
  
          break;
      }
  
      /* Make `is` point to the beginning of the image content */
      is.getline(s, '\n');
  </code></pre>
  
  <p>How to proceed?</p>