Page 1 of 1

wxCurl: sending requests.

Posted: Sat Oct 22, 2011 7:36 pm
by soMan
Hi all! I have a question: how to send a request and get a response string (or just get a response) using wxCurl? Here is a some code lines in which assertion message takes place (url option is also specified but was cut from the code below):

Code: Select all

wxCurlHTTP connection;
    connection.Init();

    connection.SetOpt(CURLOPT_AUTOREFERER, 1);
    connection.SetOpt(CURLOPT_FOLLOWLOCATION, 1);
    connection.SetOpt(CURLOPT_TIMEOUT, 10);
    connection.SetOpt(CURLOPT_URL, url.fn_str());
    connection.SetOpt(CURLOPT_USERAGENT, "MyUserAgent");
    connection.SetOpt(CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    connection.UseCookies(true);
//Direct deal with libCurl to for adding some headers.
    curl_slist headerList;
    curl_slist_append(&headerList, "Accept: text/html");
    curl_slist_append(&headerList, "Accept-Language: ru-RU");
    curl_slist_append(&headerList, "Accept-Encoding: gzip");
    curl_slist_append(&headerList, "Accept: text/html");
    curl_slist_append(&headerList, "Accept: text/html");
    connection.SetOpt(CURLOPT_HTTPHEADER, headerList);

    char buf[10000];
    size_t read = connection.Get(buf);//Здесь как понимаю buf это приемник данных с запроса.
    assert(read > 0);
    ...
As I think that Get function returns the read bytes count. I get it zero. What's the problem? So can I add HTTP headers from wxCurl but not directly from libCurl? I didn't find any solution in documentation.

Re: wxCurl: sending requests.

Posted: Tue Apr 03, 2012 2:18 pm
by caseyodonnell
Hey there...

I'm not sure what specifically you're doing, and I've been away from wxCurl for a while now, but take a look at the WebDAV sub class as an example of doing some of what you're trying to do. It may be that for one reason or another the opts/headers you're trying to send aren't getting maintained. You may be better off making a sub class of wxCurlHTTP or something along those lines.

Looking at it now, I suspect that because you're basically declaring your "Accept: text/html" strings on the stack, they've disappeared by the time the CURL calls get made. Take a look at the wxCurlBase class (in base.h) that discusses how curl setopt/slist_append doesn't take ownership of those strings. That's why the protected methods for SetHeaders()...

Best.
Casey