11 |
std::string UrlEncode(std::string url) |
std::string UrlEncode(std::string url) |
12 |
{ |
{ |
13 |
std::ostringstream ss; |
std::ostringstream ss; |
14 |
for (unsigned i=0; i<url.size(); i++) { |
for (unsigned i=0; i<url.size(); i++) |
15 |
|
{ |
16 |
char ch = url.at(i); |
char ch = url.at(i); |
17 |
if (isalnum(ch)) |
if (isalnum(ch)) |
18 |
ss << ch; |
ss << ch; |
19 |
else |
else |
20 |
ss << "%" << std::setw(2) << std::hex << (int) ch; |
ss << "%" << std::setw(2) << std::hex << std::setfill('0') <<(int) ch; |
21 |
} |
} |
22 |
return ss.str(); |
return ss.str(); |
23 |
} |
} |
30 |
char* bytes = reinterpret_cast<char*>(ptr); |
char* bytes = reinterpret_cast<char*>(ptr); |
31 |
std::vector<char>* vec = reinterpret_cast< std::vector<char>* >(stream); |
std::vector<char>* vec = reinterpret_cast< std::vector<char>* >(stream); |
32 |
|
|
33 |
|
vec->reserve( vec->size() + total); //allow vector to do a preallocation if necessary |
34 |
|
|
35 |
int i; |
int i; |
36 |
for (i=0; i<total; i++) |
for (i=0; i<total; i++) |
37 |
{ |
{ |
38 |
vec->push_back( bytes[i] ); |
vec->push_back( bytes[i] ); |
39 |
} |
} |
40 |
return i; |
return i; |
41 |
} |
} |
42 |
|
|
51 |
|
|
52 |
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg); |
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg); |
53 |
|
|
54 |
curl_easy_setopt(curl, CURLOPT_URL, url.c_str() ); |
curl_easy_setopt(curl, CURLOPT_URL, url.c_str() ); |
55 |
curl_easy_setopt(curl, CURLOPT_FAILONERROR,1); |
curl_easy_setopt(curl, CURLOPT_FAILONERROR,1); |
56 |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunction); |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunction); |
57 |
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); |
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); |
58 |
|
|
59 |
int res = curl_easy_perform(curl); |
int res = curl_easy_perform(curl); |
60 |
curl_easy_cleanup(curl); |
curl_easy_cleanup(curl); |
61 |
|
|
62 |
if (res != 0) |
if (res != 0) |
63 |
throw httpexception(errmsg); |
throw httpexception(errmsg); |