Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>By default the headers should not be written out with the body data. If your are receiving headers in your <code>write_data</code> callback, that probably means you've set either the <code>CURLOPT_HEADER</code> option or the <code>CURLOPT_WRITEHEADER</code> option. You could try resetting both of those to be safe:</p> <pre><code>curl_easy_setopt(curl, CURLOPT_HEADER, 0L); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, 0L); </code></pre> <p>If you do still want to retrieve the headers, but just not in the <code>write_data</code> callback, you can set a separate callback for your header data like this:</p> <pre><code>curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_header); </code></pre> <p>Where <code>write_header</code> is a callback function, much like your <code>write_data</code> function.</p> <pre><code>size_t write_header(void *ptr, size_t size, size_t count, void *stream) { printf("HEADER: %*.*s", size * count, size * count, ptr); return count*size; } </code></pre> <p>Note that it's important you return the number of bytes written from these callback functions otherwise curl would treat that as an error.</p> <p>If this is still not working for you, the only other explanation I can think of is that your server is returning a blank line before the header data, making it seem as if the headers are actually part of the body.</p> <p>You easily see if that is the case by testing against a known valid url (e.g. <code>http://www.example.com/</code>). If it works correctly there, then you know the fault is in your server code and not the client code.</p> <p>Having looked at your full code, though, all of that extra stuff you're seeing in your output is coming from the <code>CURLOPT_VERBOSE</code> options (which you've set twice), and <code>CURLOPT_NOPROGRESS</code> option. Just comment those out and you should get a nice clean response with nothing but the content body.</p> <p>I should also mention that there's no point in setting <code>CURLOPT_FILE</code> unless you're going to be using the <em>stream</em> parameter in the <code>write_data</code> callback. When you set the <code>CURLOPT_WRITEFUNCTION</code> callback, it replaces the default output function, so nothing will get written to the <code>CURLOPT_FILE</code> stream unless you do so yourself.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload