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 |
} |
} |
31 |
std::vector<char>* vec = reinterpret_cast< std::vector<char>* >(stream); |
std::vector<char>* vec = reinterpret_cast< std::vector<char>* >(stream); |
32 |
|
|
33 |
int i; |
int i; |
34 |
for (i=0; i<total; i++) |
for (i=0; i<total; i++) |
35 |
{ |
{ |
36 |
vec->push_back( bytes[i] ); |
vec->push_back( bytes[i] ); |
37 |
} |
} |
38 |
return i; |
return i; |
39 |
} |
} |
40 |
|
|
49 |
|
|
50 |
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg); |
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg); |
51 |
|
|
52 |
curl_easy_setopt(curl, CURLOPT_URL, url.c_str() ); |
curl_easy_setopt(curl, CURLOPT_URL, url.c_str() ); |
53 |
curl_easy_setopt(curl, CURLOPT_FAILONERROR,1); |
curl_easy_setopt(curl, CURLOPT_FAILONERROR,1); |
54 |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunction); |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunction); |
55 |
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); |
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); |
56 |
|
|
57 |
int res = curl_easy_perform(curl); |
int res = curl_easy_perform(curl); |
58 |
curl_easy_cleanup(curl); |
curl_easy_cleanup(curl); |
59 |
|
|
60 |
if (res != 0) |
if (res != 0) |
61 |
throw httpexception(errmsg); |
throw httpexception(errmsg); |