void CurlEasy::SetPostBytes(const void* data, int length) { int code = curl_easy_setopt(m_curl, CURLOPT_POSTFIELDSIZE, length); // Set post data length VERIFY_CURL_CODE(code); // CURLOPT_COPYPOSTFIELDS to copy the data // CURLOPT_POSTFIELDS for static resource code = curl_easy_setopt(m_curl, CURLOPT_COPYPOSTFIELDS, data); // Set post data VERIFY_CURL_CODE(code); }
void CurlEasy::SetProgressCallback(ref<ICurlProgress> prog) { int code = curl_easy_setopt(m_curl, CURLOPT_NOPROGRESS, 0); VERIFY_CURL_CODE(code); code = curl_easy_setopt(m_curl, CURLOPT_PROGRESSFUNCTION, CurlProgressCallback); VERIFY_CURL_CODE(code); code = curl_easy_setopt(m_curl, CURLOPT_PROGRESSDATA, prog.__GetPointer()); VERIFY_CURL_CODE(code); }
void CurlEasy::Request(ref<ICurlResponseWriter> response) { int code = 0; // Write headers struct curl_slist *headers = NULL; if (m_headers.size() != 0) { typedef std::vector<std::string>::iterator headers_it; foreach_it (headers_it, it, m_headers.begin(), m_headers.end()) headers = curl_slist_append(headers, it->c_str()); code = curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, headers); VERIFY_CURL_CODE(code); } // Set response receiver ref<ICurlContentWriter> cntwr = response->GetContentWriter(); cntwr->Reset(); code = curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, CurlDataWriteCallback); VERIFY_CURL_CODE(code); code = curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, cntwr.__GetPointer()); VERIFY_CURL_CODE(code); // Set response header receiver if (m_ops & CCO_ResponseHeaders) { int code = curl_easy_setopt(m_curl, CURLOPT_HEADERFUNCTION, CurlHeaderWriteCallback); VERIFY_CURL_CODE(code); code = curl_easy_setopt(m_curl, CURLOPT_WRITEHEADER, response.__GetPointer()); VERIFY_CURL_CODE(code); } // Perform action code = curl_easy_perform(m_curl); VERIFY_CURL_CODE(code); // Read response information long responseCode = 0; code = curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &responseCode); VERIFY_CURL_CODE(code); response->SetResponseCode((int)responseCode); double speed; code = curl_easy_getinfo(m_curl, CURLINFO_SPEED_DOWNLOAD, &speed); VERIFY_CURL_CODE(code); response->SetSpeedDownload(speed); code = curl_easy_getinfo(m_curl, CURLINFO_SPEED_UPLOAD, &speed); VERIFY_CURL_CODE(code); response->SetSpeedUpload(speed); // Clean up if (headers != NULL) curl_slist_free_all(headers); // free the header list }
void CurlEasy::SetPutStream(ref<Stream> istream) { m_istream = istream; m_istream->Seek(0, Stream::SeekBegin); int code = curl_easy_setopt(m_curl, CURLOPT_UPLOAD, 1); VERIFY_CURL_CODE(code); code = curl_easy_setopt(m_curl, CURLOPT_READFUNCTION, CurlDataReadCallback); VERIFY_CURL_CODE(code); code = curl_easy_setopt(m_curl, CURLOPT_READDATA, m_istream.__GetPointer()); VERIFY_CURL_CODE(code); }
void CurlEasy::SetProxy(stringx proxyHost, UINT proxyPort, CurlProxyType proxyType /* = CPT_SOCKS4 */) { stringx hostPort = proxyHost + __X(":") + Converter::ToString(proxyPort); CURLcode code = curl_easy_setopt( m_curl, CURLOPT_PROXY, Encoding::get_UTF8()->FromUnicode(hostPort).c_str() ); VERIFY_CURL_CODE(code); code = curl_easy_setopt( m_curl, CURLOPT_PROXYTYPE, proxyType == CPT_SOCKS4 ? CURLPROXY_SOCKS4 : CURLPROXY_SOCKS5 ); VERIFY_CURL_CODE(code); }
void CurlEasy::GlobalInit() { #if defined(X_OS_WINDOWS) long flags = CURL_GLOBAL_WIN32; #else long flags = CURL_GLOBAL_NOTHING; #endif int code = curl_global_init(flags); VERIFY_CURL_CODE(code); }
void CurlEasy::SetCustomRequest(PCSTR method) { int code = curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, method); VERIFY_CURL_CODE(code); }
void CurlEasy::SetTimeOut(int seconds) { int code = curl_easy_setopt(m_curl, CURLOPT_TIMEOUT, seconds); VERIFY_CURL_CODE(code); }
void CurlEasy::SetUrl(const char* url) { int code = curl_easy_setopt(m_curl, CURLOPT_URL, url); VERIFY_CURL_CODE(code); }
void CurlEasy::SetMaxRedirs(long amount) { CURLcode code = curl_easy_setopt(m_curl, CURLOPT_MAXREDIRS, amount); VERIFY_CURL_CODE(code); }
void CurlEasy::SetNoBody(bool bNobody) { CURLcode code = curl_easy_setopt(m_curl, CURLOPT_NOBODY, bNobody); VERIFY_CURL_CODE(code); }