cURL / Mailing Lists / curl-library / Single Mail

curl-library

Binary HTTP Response Head crashes library

From: Woods <woods.biz_at_gmail.com>
Date: Tue, 21 Feb 2012 21:29:02 +0800

Dear all,

I have a Http server that returns binary Http response is I use HTTP
HEAD command to request.
Below is the capture from wireshark.
----------------------------------
HEAD / HTTP/1.1
Host: 91.208.xxx.xxx
Accept: */*

!H.G..^...q. Zf.....3H2..f...M.nE..uO.`......g.[.....]..h.B&G<....
----------------------------------------------

My code is here. Above response crashes the CURLOPT_WRITEHEADER call
back function sWriteFunction.
Any suggestion on this? Thanks.

#include <assert.h>
#include <stdio.h>
#include <iostream>
#include <sstream>

extern "C"
{
#include <curl/curl.h>
}

using namespace std;

size_t sWriteFunction(void *p_pPtr, size_t p_Size, size_t p_Nmemb,
void *p_pParam)
{
    stringstream *pStream = reinterpret_cast<stringstream*>(p_pParam);
    int bytesToRead = p_Size * p_Nmemb;
    pStream->write(reinterpret_cast<char*>(p_pPtr), bytesToRead);
    return bytesToRead;
}

int main(int argc, char* argv[])
{
    curl_global_init(CURL_GLOBAL_ALL);
    CURL* curl = curl_easy_init();

    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
    curl_easy_setopt(curl, CURLOPT_URL, "http://91.208.xxx.xxx");
    curl_easy_setopt(curl, CURLOPT_PORT, 80);
    curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);

    stringstream headerStream(stringstream::in | stringstream::out);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, sWriteFunction);
    curl_easy_setopt(curl, CURLOPT_WRITEHEADER, &headerStream);

    CURLcode res = curl_easy_perform(curl);

    curl_easy_cleanup(curl);
}

-- 
Woods
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2012-02-21