wxCurl: sending requests.

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
soMan
In need of some credit
In need of some credit
Posts: 4
Joined: Mon Aug 22, 2011 4:57 pm

wxCurl: sending requests.

Post 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.
caseyodonnell
Knows some wx things
Knows some wx things
Posts: 31
Joined: Fri Sep 10, 2004 1:03 pm
Location: Troy, NY
Contact:

Re: wxCurl: sending requests.

Post 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
Post Reply