tags:

views:

156

answers:

1

Here's the code (extracted from an existing application):

CURL *curl = curl_easy_init();
_ASSERTE(curl);

string url = "http://127.0.0.1:8000/";

char *data = "mode=test";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_URL, url);
CURLcode res = curl_easy_perform(curl);

bool success = (res == CURLE_OK);

curl_easy_cleanup(curl);

The value of res is CURLE_URL_MALFORMAT. Is this URL not compatible with curl?

A: 

Ah, simple mistake, I need to pass char * to curl_easy_setopt and not string. To fix this I've just used .c_str() like so:

CURL *curl = curl_easy_init();
_ASSERTE(curl);

string url = "http://127.0.0.1:8000/";

char *data = "mode=test";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
CURLcode res = curl_easy_perform(curl);

bool success = (res == CURLE_OK);

curl_easy_cleanup(curl);
nbolton