#include "HttpCurl.h"
#include "easycurl.h"
bool HttpCurlPost::Post(const char* url, const void* postdata, size_t datasize)
{
	CURLcode code = CURLE_FAILED_INIT;
	if (_curl.Init()) {
		_curl.SetTimeOut(20);
		_curl.SetURL(url);
		_curl.EnablePost(true);

		if( 0 == strncmp(url,"https:", 6))
			_curl.EnableHttps(NULL);

		ReadChunk read_chunk((const char*)postdata, datasize);

		EasyCurlSender sender;
		sender._callback = NULL;
		sender.readthunk = &read_chunk;
		_curl.SetSender(&sender);
		_curl.SetPostFieldsize(datasize);

		curl_slist *plist = curl_slist_append(NULL, "Content-Type:application/json;charset=UTF-8");
		curl_easy_setopt(_curl.GetHandle(), CURLOPT_HTTPHEADER, plist);
		

		_date.clear();
		EasyCurlRecver recver;
		recver._callback = NULL;
		recver.writethunk = &_date;
		_curl.SetRecver(&recver);
		code =_curl.Perform();
	}
	return code ==  CURLE_OK;
}
