|
@@ -197,7 +197,7 @@ namespace oxygine
|
|
|
return size;
|
|
return size;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- HttpRequestTaskCURL::HttpRequestTaskCURL() : _easy(0), _handle(0), _httpHeaders(NULL)
|
|
|
|
|
|
|
+ HttpRequestTaskCURL::HttpRequestTaskCURL() : _easy(0), _handle(0), _httpHeaders(0)
|
|
|
{
|
|
{
|
|
|
_easy = curl_easy_init();
|
|
_easy = curl_easy_init();
|
|
|
}
|
|
}
|
|
@@ -211,12 +211,12 @@ namespace oxygine
|
|
|
if (_easy)
|
|
if (_easy)
|
|
|
curl_easy_cleanup(_easy);
|
|
curl_easy_cleanup(_easy);
|
|
|
_easy = 0;
|
|
_easy = 0;
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- void _addHeader(const std::string& key, const std::string& value) {
|
|
|
|
|
- _httpHeaders = curl_slist_append(_httpHeaders, key + ": " + value);
|
|
|
|
|
|
|
+ if (_httpHeaders)
|
|
|
|
|
+ curl_slist_free_all(_httpHeaders);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
void HttpRequestTaskCURL::_run()
|
|
void HttpRequestTaskCURL::_run()
|
|
|
{
|
|
{
|
|
|
curl_easy_setopt(_easy, CURLOPT_URL, _url.c_str());
|
|
curl_easy_setopt(_easy, CURLOPT_URL, _url.c_str());
|
|
@@ -228,38 +228,17 @@ namespace oxygine
|
|
|
curl_easy_setopt(_easy, CURLOPT_FOLLOWLOCATION, true);
|
|
curl_easy_setopt(_easy, CURLOPT_FOLLOWLOCATION, true);
|
|
|
curl_easy_setopt(_easy, CURLOPT_NOPROGRESS, 0);
|
|
curl_easy_setopt(_easy, CURLOPT_NOPROGRESS, 0);
|
|
|
|
|
|
|
|
- //curl_slist *header = curl_slist_append(0, "hello");
|
|
|
|
|
- //curl_easy_setopt(_easy, CURLOPT_HEADER, header);
|
|
|
|
|
- if(!_httpHeaders) {
|
|
|
|
|
- httpHeaders = curl_slist_append(_httpHeaders, "Content-Type: text/plain");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- curl_easy_setopt(_easy, CURLOPT_HTTPHEADER, _httpHeaders);
|
|
|
|
|
-
|
|
|
|
|
- if (!_postData.empty()){
|
|
|
|
|
- // curl_slist* headers = NULL; // init to NULL is important
|
|
|
|
|
- //headers = curl_slist_append(headers, "Accept:")
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
- //curl_easy_setopt(_easy, CURLOPT_PORT, 4002);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //curl_easy_setopt(_easy, CURLOPT_VERBOSE, 1);
|
|
|
|
|
- //curl_easy_setopt(_easy, CURLOPT_POST, 1);
|
|
|
|
|
- //_sendPostData.push_back(0);
|
|
|
|
|
- //char *p = curl_escape(&_postData.front(), _postData.size());
|
|
|
|
|
- //log::messageln("data: %s", p);
|
|
|
|
|
- //log::messageln("data: %s", &_sendPostData.front());
|
|
|
|
|
- //curl_easy_setopt(_easy, CURLOPT_POSTFIELDS, p);
|
|
|
|
|
- //curl_easy_setopt(_easy, CURLOPT_TIMEOUT, 9999);
|
|
|
|
|
|
|
+ if (!_postData.empty())
|
|
|
|
|
+ {
|
|
|
curl_easy_setopt(_easy, CURLOPT_POSTFIELDS, &_postData.front());
|
|
curl_easy_setopt(_easy, CURLOPT_POSTFIELDS, &_postData.front());
|
|
|
curl_easy_setopt(_easy, CURLOPT_POSTFIELDSIZE, _postData.size());
|
|
curl_easy_setopt(_easy, CURLOPT_POSTFIELDSIZE, _postData.size());
|
|
|
-
|
|
|
|
|
- //curl_easy_setopt(_easy, CURLOPT_TCP_KEEPALIVE, 1);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- curl_easy_setopt(_easy, CURLOPT_HEADER, 0);
|
|
|
|
|
|
|
+ for (size_t i = 0; i < _headers.size(); ++i)
|
|
|
|
|
+ _httpHeaders = curl_slist_append(_httpHeaders, (_headers[i].first + ": " + _headers[i].second).c_str());
|
|
|
|
|
+
|
|
|
|
|
+ curl_easy_setopt(_easy, CURLOPT_HTTPHEADER, _httpHeaders);
|
|
|
|
|
|
|
|
addRef();
|
|
addRef();
|
|
|
_messages.post(0, _easy, 0);
|
|
_messages.post(0, _easy, 0);
|