예제 #1
0
    void prepare_send_data() {
        assert(m_post_form.empty());

        if(!m_send_data.empty()) {
            assert(!m_send_file);
            curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE,  static_cast<curl_off_t>(m_send_data.size()));
            curl_easy_setopt(handle, CURLOPT_UPLOAD,            1);
        }

        if(m_send_file) {
            assert(m_send_data.empty());

            // set the FILE pointer as read data in CURL
            curl_easy_setopt(handle, CURLOPT_READFUNCTION,      nullptr);
            curl_easy_setopt(handle, CURLOPT_READDATA,          m_send_file.get());
            curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE,  static_cast<curl_off_t>(m_send_file_size));
            curl_easy_setopt(handle, CURLOPT_UPLOAD,            1);
        }
    }
예제 #2
0
    void request_post() {
        if(m_post_form.empty()) {
            request_put();
        } else {
            assert(m_send_data.empty());
            assert(!m_send_file);

            for(auto&& i : m_post_form) {
                add_form_data(i.name, i.content, i.type);
            }
            curl_easy_setopt(handle, CURLOPT_HTTPPOST, post_data);
        }
    }
예제 #3
0
 void request_get() {
     assert(!m_send_file);
     assert(m_send_data.empty());
     assert(m_post_form.empty());
 }