static PcsBool cb_get_verify_code_byurlc(unsigned char *ptr, size_t size, char *captcha, size_t captchaSize, void *state) { CURL *curl; CURLcode res; struct curl_httppost *formpost = 0; struct curl_httppost *lastptr = 0; char *html = NULL; curl = curl_easy_init(); if (!curl) { puts("Cannot init the libcurl."); return PcsFalse; } curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); # define USAGE "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36" curl_easy_setopt(curl, CURLOPT_USERAGENT, USAGE); /* tell libcurl to follow redirection */ //res = curl_easy_setopt(pcs->curl, CURLOPT_COOKIEFILE, cookie_folder); //curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); curl_formadd(&formpost, &lastptr, CURLFORM_PTRNAME, "photofile", CURLFORM_BUFFER, "verify_code.gif", CURLFORM_BUFFERPTR, ptr, CURLFORM_BUFFERLENGTH, (long)size, CURLFORM_END); curl_easy_setopt(curl, CURLOPT_URL, "http://urlc.cn/g/upload.php"); curl_easy_setopt(curl, CURLOPT_POST, 1); //curl_easy_setopt(curl, CURLOPT_COOKIE, ""); curl_easy_setopt(curl, CURLOPT_HEADER , 1); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &cb_get_verify_code_byurlc_curl_write); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &html); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_REFERER , "http://urlc.cn/g/"); res = curl_easy_perform(curl); if(res != CURLE_OK) { printf("Cannot upload the image to http://urlc.cn/g/\n%s\n", curl_easy_strerror(res)); if (html) pcs_free(html); curl_formfree(formpost); curl_easy_cleanup(curl); return PcsFalse; } curl_formfree(formpost); curl_easy_cleanup(curl); if (!html) { printf("Cannot get the response from http://urlc.cn/g/\n"); return PcsFalse; } printf("\n%s\n\n", html); pcs_free(html); printf("You can access the verify code image from the url that can find from above html, please input the text in the image: "); get_string_from_std_input(captcha, captchaSize); return PcsTrue; }
static int testMultithreadedPoolPost () { struct MHD_Daemon *d; CURL *c; char buf[2048]; struct CBC cbc; CURLcode errornum; struct curl_httppost *pd; cbc.buf = buf; cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1081/hello_world"); curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); pd = make_form (); curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); if (oneone) curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); else curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L); // NOTE: use of CONNECTTIMEOUT without also // setting NOSIGNAL results in really weird // crashes on my system! curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); if (CURLE_OK != (errornum = curl_easy_perform (c))) { fprintf (stderr, "curl_easy_perform failed: `%s'\n", curl_easy_strerror (errornum)); curl_easy_cleanup (c); curl_formfree (pd); MHD_stop_daemon (d); return 32; } curl_easy_cleanup (c); curl_formfree (pd); MHD_stop_daemon (d); if (cbc.pos != strlen ("/hello_world")) return 64; if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) return 128; return 0; }
/******************************************************************** * Post Formdata Run * ********************************************************************/ CURLcode CHttp::DoHttpPostFormData() { CURL *curl = curl_easy_init(); /// 使用multi-parts form post curl_httppost *post = NULL; curl_httppost *last = NULL; /// 文本数据 CMapKeyValue::iterator it1 = m_mapPostData.begin(); while (it1 != m_mapPostData.end()) { curl_formadd(&post, &last, CURLFORM_COPYNAME, (it1->first).c_str(), CURLFORM_COPYCONTENTS,(it1->second).c_str(), CURLFORM_END); it1++; } /// 文件数据 CMapKeyValue::iterator it2 = m_mapPostFile.begin(); while (it2 != m_mapPostFile.end()) { curl_formadd(&post, &last, CURLFORM_COPYNAME, (it2->first).c_str(), CURLFORM_FILE, (it2->second).c_str(), CURLFORM_END); it2++; } curl_easy_setopt(curl, CURLOPT_URL, m_strUrl.c_str()); curl_easy_setopt(curl, CURLOPT_HTTPPOST, post); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CHttp::ProcessResult); curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); CURLcode eErrorCode = curl_easy_perform(curl); curl_formfree(post); curl_easy_cleanup(curl); return eErrorCode; }
void FZHttpPost::SendPost() { // Send current array contents to server // The 'user' (=fDBUserName) and 'category' (=fDBCategory) fields are added to the POST if(!fPostPairs) return;// nothing to send // add the 2 'header' elements to the POST (=> corresponds to value of fNHdrElements) // N.B. if the number of these elements changes you should modify fNHdrElements! AddKeyValuePair("user",fDBUserName); AddKeyValuePair("category",fDBCategory); //std::cout << "Sending " << fLineNumber+1 << "lines (" << fPostPairs << " key-value pairs) to server" << std::endl; curl_easy_setopt(fCURL, CURLOPT_HTTPPOST, formpost); /* CURLcode res = */ curl_easy_perform(fCURL); /* if (res != CURLE_OK) std::cout << "curl_easy_perform() failed: " << curl_easy_strerror(res); */ curl_formfree(formpost); formpost = lastptr = NULL; // reset line number (this is also the first array index, i.e. 'par[fLineNumber][some-key]') fLineNumber=0; // reset total number of key-value pairs in post fPostPairs=0; }
/** * Send file to xsnippet.org * * @param filename -- a path to file * @return a snippet url */ std::string sendFile(const char* filename) { const char* API_URL = "http://www.xsnippet.org/new"; std::string snippetUrl = ""; curl_global_init(CURL_GLOBAL_ALL); // set form fields curl_httppost* formpost = 0; curl_httppost* lastptr = 0; curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "file", CURLFORM_FILE, filename, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "author", CURLFORM_COPYCONTENTS, getUserName().c_str(), CURLFORM_END); // send data, return url and clean-up CURL* curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, API_URL); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, headerHandler); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, &snippetUrl); CURLcode res = curl_easy_perform(curl); curl_easy_cleanup(curl); curl_formfree(formpost); } return snippetUrl; }
void URL_cleanup(struct URL_Request *u) { if (u->headerlist != NULL) curl_slist_free_all(u->headerlist); if (u->formpost != NULL) curl_formfree(u->formpost); curl_easy_cleanup(u->curl); }
bool CurlWrapper::upload_file(const std::string &url, const std::string &path, const progress_callback_t &progress_callback) { auto curl = std::shared_ptr<CURL>(curl_easy_init(), curl_easy_cleanup); CURLcode res; if (nullptr != curl) { struct dl_up_progress prog; prog.progress_callback = progress_callback; curl_httppost *post = NULL; curl_httppost *last = NULL; struct curl_slist *chunk = NULL; // avoid sending 'Expect: 100-Continue' header, required by some server implementations chunk = curl_slist_append(chunk, "Expect:"); // disable chunked upload chunk = curl_slist_append(chunk, "Content-Encoding: "); // to allow efficient file upload, we need to add the file size to the header std::string filesize_header = "File-Size: " + to_string(get_file_size(path)); chunk = curl_slist_append(chunk, filesize_header.c_str()); curl_formadd( &post, &last, CURLFORM_COPYNAME, "file", CURLFORM_FILE, path.c_str(), CURLFORM_END); curl_easy_setopt(curl.get(), CURLOPT_CONNECTTIMEOUT, 5L); curl_easy_setopt(curl.get(), CURLOPT_PROGRESSFUNCTION, upload_progress_update); curl_easy_setopt(curl.get(), CURLOPT_PROGRESSDATA, &prog); curl_easy_setopt(curl.get(), CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, chunk); curl_easy_setopt(curl.get(), CURLOPT_URL, url.c_str()); curl_easy_setopt(curl.get(), CURLOPT_HTTPPOST, post); curl_easy_setopt(curl.get(), CURLOPT_NOPROGRESS, 0L); res = curl_easy_perform(curl.get()); curl_slist_free_all(chunk); curl_formfree(post); if (res == CURLcode::CURLE_OK) { if (nullptr != progress_callback) { progress_callback(100, Status::Finished, CURLcode::CURLE_OK); } return true; } else { if (nullptr != progress_callback) { progress_callback(0, Status::Error, res); } LogErr() << "Error while uploading file, curl error code: " << curl_easy_strerror(res); return false; } } else { LogErr() << "Error: cannot start uploading because of curl initialization error."; return false; } }
/** * Submit a run * @param bott Bott file for Run info * @return Submit status */ int LOJJudger::submit(Bott * bott) { // prepare form for post struct curl_httppost * formpost = NULL; struct curl_httppost * lastptr = NULL; curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "sub_problem", CURLFORM_COPYCONTENTS, bott->Getvid().c_str(), CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "language", CURLFORM_COPYCONTENTS, convertLanguage(bott->Getlanguage()).c_str(), CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "code", CURLFORM_COPYCONTENTS, bott->Getsrc().c_str(), CURLFORM_END); prepareCurl(); curl_easy_setopt(curl, CURLOPT_URL, "http://www.lightoj.com/volume_submit.php"); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); performCurl(); curl_formfree(formpost); // check submit status string html = loadAllFromFile(tmpfilename); if (html.find( "<script>location.href='volume_usersubmissions.php'</script>") == string::npos) { return SUBMIT_OTHER_ERROR; } return VirtualJudger::SUBMIT_NORMAL; }
/** * Free a fetch structure and associated resources. */ static void fetch_curl_free(void *vf) { struct curl_fetch_info *f = (struct curl_fetch_info *)vf; int i; if (f->curl_handle) { curl_easy_cleanup(f->curl_handle); } nsurl_unref(f->url); lwc_string_unref(f->host); free(f->location); free(f->cookie_string); free(f->realm); if (f->headers) { curl_slist_free_all(f->headers); } free(f->post_urlenc); if (f->post_multipart) { curl_formfree(f->post_multipart); } for (i = 0; i < MAX_CERTS && f->cert_data[i].cert; i++) { f->cert_data[i].cert->references--; if (f->cert_data[i].cert->references == 0) { X509_free(f->cert_data[i].cert); } } free(f); }
/** * Send a Curl httppost * @return 1 on success, 0 on error. * @ingroup Ecore_Con_Url_Group */ EAPI int ecore_con_url_http_post_send(Ecore_Con_Url *url_con, void *httppost) { #ifdef HAVE_CURL if (url_con->post) curl_formfree(url_con->post); url_con->post = NULL; if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) { ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_http_post_send"); return 0; } url_con->post = httppost; if (url_con->active) return 0; if (!url_con->url) return 0; curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPPOST, httppost); return ecore_con_url_send(url_con, NULL, 0, NULL); #else return 0; url_con = NULL; #endif }
void JavaUpload::changeActive(bool nowActive) { m_buffer.clear(); if (nowActive) { m_file.setFileName(m_strSource); if (!m_file.open(QIODevice::ReadOnly)) { m_strMessage = m_file.errorString(); setState(Failed); return; } // call Java m_plugin->call("processFile", JSignature().addString(), JArgs() << m_strSource); } else { CurlPoller::instance()->removeTransfer(this, true); resetStatistics(); if(m_curl) m_curl = 0; if(m_postData) { curl_formfree(m_postData); m_postData = 0; } m_plugin->abort(); } }
bool HTTPClient::Clean(void* _ptr) { if(curl) { if(!is_raise_error_multi_handle) curl_multi_remove_handle(HTTPManager::Share()->GetCURLMulti(), curl); curl_easy_cleanup(curl); curl = NULL; } if(header_chunk) { curl_slist_free_all(header_chunk); header_chunk = NULL; } if(http_post) { curl_formfree(http_post); http_post = NULL; } if(body.is_open()) { body.close(); CLOSE_FD(); } if(header.is_open()) { header.close(); CLOSE_FD(); } if(access(body_file_path.c_str(), F_OK) == 0) remove(body_file_path.c_str()); if(access(header_file_path.c_str(), F_OK) == 0) remove(header_file_path.c_str()); return true; }
/* * curl_formfree() is an external function to free up a whole form post * chain */ void curl_formfree(struct curl_httppost *form) { struct curl_httppost *next; if(!form) /* no form to free, just get out of this */ return; do { next=form->next; /* the following form line */ /* recurse to sub-contents */ if(form->more) curl_formfree(form->more); if(!(form->flags & HTTPPOST_PTRNAME) && form->name) free(form->name); /* free the name */ if(!(form->flags & (HTTPPOST_PTRCONTENTS|HTTPPOST_BUFFER|HTTPPOST_CALLBACK)) && form->contents) free(form->contents); /* free the contents */ if(form->contenttype) free(form->contenttype); /* free the content type */ if(form->showfilename) free(form->showfilename); /* free the faked file name */ free(form); /* free the struct */ } while((form = next) != NULL); /* continue */ }
static Qiniu_Error Qiniu_Io_call( Qiniu_Client* self, Qiniu_Io_PutRet* ret, struct curl_httppost* formpost) { Qiniu_Error err; CURL* curl = Qiniu_Client_reset(self); struct curl_slist* headers = curl_slist_append(NULL, "Expect:"); curl_easy_setopt(curl, CURLOPT_URL, QINIU_UP_HOST); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); err = Qiniu_callex(curl, &self->b, &self->root, Qiniu_False, &self->respHeader); if (err.code == 200 && ret != NULL) { ret->hash = Qiniu_Json_GetString(self->root, "hash", NULL); ret->key = Qiniu_Json_GetString(self->root, "key", NULL); } curl_formfree(formpost); /* * Bug No.(4718) Wang Xiaotao 2013\10\17 17:46:07 * Change for : free variable 'headers' * Reason : memory leak! */ curl_slist_free_all(headers); return err; }
void ckl_transport_free(ckl_transport_t *t) { curl_easy_cleanup(t->curl); curl_formfree(t->formpost); curl_slist_free_all(t->headerlist); free(t); }
CPost::~CPost() { if (mFormPost) { curl_formfree(mFormPost); } }
int main(int argc, char *argv[]) { CURL *curl; CURLcode res; struct curl_httppost *formpost = NULL; struct curl_httppost *lastptr = NULL; struct curl_slist *headerlist = NULL; static const char buf[] = "Expect:"; curl_global_init(CURL_GLOBAL_ALL); /* Fill in the file upload field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "sendfile", CURLFORM_FILE, "postit2.c", CURLFORM_END); /* Fill in the filename field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "filename", CURLFORM_COPYCONTENTS, "postit2.c", CURLFORM_END); /* Fill in the submit field too, even if this is rarely needed */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "send", CURLFORM_END); curl = curl_easy_init(); /* initalize custom header list (stating that Expect: 100-continue is not wanted */ headerlist = curl_slist_append(headerlist, buf); if (curl) { /* what URL that receives this POST */ curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/examplepost.cgi"); if ((argc == 2) && (!strcmp(argv[1], "noexpectheader"))) /* only disable 100-continue header if explicitly requested */ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); /* Check for errors */ if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); /* then cleanup the formpost chain */ curl_formfree(formpost); /* free slist */ curl_slist_free_all(headerlist); } return 0; }
int multi_part_curl_process(const user_opt *u, const send_opt *s, response_struct *output) { CURL *curl; CURLcode res; char url[1024]; struct curl_httppost *formpost = NULL; struct curl_httppost *lastptr = NULL; struct curl_slist *headerlist = NULL; response_struct response; /* initialize response struct */ response.memory = (char*)malloc(1); /* will be grown as needed by the realloc above */ response.size = 0; /* no data at this point */ /* set url and initilize curl */ sprintf(url, "%s/%s/%s", "http://api.coolsms.co.kr/sms", VER, "send"); curl = curl_easy_init(); /* set values to curl_form */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "subject", CURLFORM_COPYCONTENTS, s->subject, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "api_key", CURLFORM_COPYCONTENTS, u->api_key, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "salt", CURLFORM_COPYCONTENTS, u->salt, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "signature", CURLFORM_COPYCONTENTS, u->signature, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "timestamp", CURLFORM_COPYCONTENTS, u->timestamp, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "image", CURLFORM_FILE, s->image, CURLFORM_CONTENTTYPE, "image/jpeg", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "to", CURLFORM_COPYCONTENTS, s->to, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "from", CURLFORM_COPYCONTENTS, s->from, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "text", CURLFORM_COPYCONTENTS, s->text, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "charset", CURLFORM_COPYCONTENTS, s->charset, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "type", CURLFORM_COPYCONTENTS, s->type, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "refname", CURLFORM_COPYCONTENTS, s->refname, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "datetime", CURLFORM_COPYCONTENTS, s->datetime, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "mid", CURLFORM_COPYCONTENTS, s->mid, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "gid", CURLFORM_COPYCONTENTS, s->gid, CURLFORM_END); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* CURLOPT_VERBOSE shows infomation about connected server. USEFUL for debugging */ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response); curl_easy_setopt(curl, CURLOPT_USERAGENT, "REST SDK C&CPP/1.0"); res = curl_easy_perform(curl); /* Check for errors */ if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); else printf("%lu bytes retrieved\n", (long)response.size); *output = response; /* then cleanup curl, formpost and headerlist */ curl_easy_cleanup(curl); curl_formfree(formpost); curl_slist_free_all(headerlist); } return res; }
/* Cleanup after each request by resetting the Curl handle and deallocating * all request related objects such as the header slist. */ static VALUE cleanup(VALUE self) { struct curl_state *state = get_curl_state(self); curl_easy_reset(state->handle); if (state->headers) { curl_slist_free_all(state->headers); state->headers = NULL; } if (state->download_file) { fclose(state->download_file); state->download_file = NULL; } if (state->request_body_file) { fclose(state->request_body_file); state->request_body_file = NULL; } if (state->post) { curl_formfree(state->post); state->post = NULL; state->last = NULL; } state->upload_buf = NULL; return Qnil; }
void JavaUpload::curlInit() { if(m_curl) curl_easy_cleanup(m_curl); m_curl = curl_easy_init(); //curl_easy_setopt(m_curl, CURLOPT_POST, true); if(getSettingsValue("httpftp/forbidipv6").toInt() != 0) curl_easy_setopt(m_curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_easy_setopt(m_curl, CURLOPT_USERAGENT, "FatRat/" VERSION); curl_easy_setopt(m_curl, CURLOPT_ERRORBUFFER, m_errorBuffer); //curl_easy_setopt(m_curl, CURLOPT_SEEKFUNCTION, seek_function); curl_easy_setopt(m_curl, CURLOPT_SEEKDATA, this); curl_easy_setopt(m_curl, CURLOPT_DEBUGDATA, this); curl_easy_setopt(m_curl, CURLOPT_VERBOSE, true); //curl_easy_setopt(m_curl, CURLOPT_PROGRESSFUNCTION, anti_crash_fun); curl_easy_setopt(m_curl, CURLOPT_CONNECTTIMEOUT, 10); curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, CurlUser::write_function); curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, static_cast<CurlUser*>(this)); curl_easy_setopt(m_curl, CURLOPT_READFUNCTION, CurlUser::read_function); curl_easy_setopt(m_curl, CURLOPT_READDATA, static_cast<CurlUser*>(this)); curl_easy_setopt(m_curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_easy_setopt(m_curl, CURLOPT_HEADERFUNCTION, process_header); curl_easy_setopt(m_curl, CURLOPT_WRITEHEADER, this); if(m_postData) { curl_formfree(m_postData); m_postData = 0; } }
HTTPFetchOngoing::~HTTPFetchOngoing() { if (multi) { CURLMcode mres = curl_multi_remove_handle(multi, curl); if (mres != CURLM_OK) { errorstream << "curl_multi_remove_handle" << " returned error code " << mres << std::endl; } } // Set safe options for the reusable cURL handle curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, httpfetch_discardfunction); curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL); if (http_header) { curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL); curl_slist_free_all(http_header); } if (post) { curl_easy_setopt(curl, CURLOPT_HTTPPOST, NULL); curl_formfree(post); } // Store the cURL handle for reuse pool->free(curl); }
wxString Paste2Pastebin( const wxString& message ) { #ifndef SL_QT_MODE #ifndef __WXMAC__ wxStringOutputStream response; wxStringOutputStream rheader; CURL *curl_handle; curl_handle = curl_easy_init(); struct curl_slist* m_pHeaders = NULL; struct curl_httppost* m_pPostHead = NULL; struct curl_httppost* m_pPostTail = NULL; static const char* url = "http://pastebin.com/api_public.php"; // these header lines will overwrite/add to cURL defaults m_pHeaders = curl_slist_append(m_pHeaders, "Expect:") ; //we need to keep these buffers around for curl op duration wxCharBuffer message_buffer = message.mb_str(); wxCharBuffer nick_buffer = sett().GetServerAccountNick( sett().GetDefaultServer() ).mb_str(); curl_formadd(&m_pPostHead, &m_pPostTail, CURLFORM_COPYNAME, "paste_code", CURLFORM_COPYCONTENTS, (const char*)message_buffer, CURLFORM_END); curl_formadd(&m_pPostHead, &m_pPostTail, CURLFORM_COPYNAME, "paste_subdomain", CURLFORM_COPYCONTENTS, "sl", CURLFORM_END); curl_formadd(&m_pPostHead, &m_pPostTail, CURLFORM_COPYNAME, "paste_name", CURLFORM_COPYCONTENTS, (const char*)nick_buffer, CURLFORM_END); curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, m_pHeaders); curl_easy_setopt(curl_handle, CURLOPT_URL, url ); // curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, wxcurl_stream_write); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&response); curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (void *)&rheader); curl_easy_setopt(curl_handle, CURLOPT_POST, TRUE); curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, m_pPostHead); CURLcode ret = curl_easy_perform(curl_handle); wxLogError( rheader.GetString() ); /* cleanup curl stuff */ curl_easy_cleanup(curl_handle); curl_formfree(m_pPostHead); if(ret == CURLE_OK) return response.GetString(); else #endif #endif return wxEmptyString; }
void CurlWrapper::SendResultsToWebpage(const char* fileid, const char* status, const char* detailstatus, const char* time, const char* memory, const char* numberofwrongtestcases) { struct curl_httppost *formpost = NULL; struct curl_httppost *lastptr = NULL; struct curl_slist *headerlist = NULL; static const char buf[] = "Expect: "; //curl_global_init(CURL_GLOBAL_ALL); /* Fill in the POST fields */ curl_formadd( &formpost, &lastptr, CURLFORM_COPYNAME, "username", CURLFORM_COPYCONTENTS, USERNAME, CURLFORM_END); curl_formadd( &formpost, &lastptr, CURLFORM_COPYNAME, "password", CURLFORM_COPYCONTENTS, PASSWORD, CURLFORM_END); curl_formadd( &formpost, &lastptr, CURLFORM_COPYNAME, "fileid", CURLFORM_COPYCONTENTS, fileid, CURLFORM_END); curl_formadd( &formpost, &lastptr, CURLFORM_COPYNAME, "status", CURLFORM_COPYCONTENTS, status, CURLFORM_END); //printf("%s\n", detailstatus); curl_formadd( &formpost, &lastptr, CURLFORM_COPYNAME, "detailstatus", CURLFORM_PTRCONTENTS, detailstatus, CURLFORM_END); curl_formadd( &formpost, &lastptr, CURLFORM_COPYNAME, "time", CURLFORM_COPYCONTENTS, time, CURLFORM_END); curl_formadd( &formpost, &lastptr, CURLFORM_COPYNAME, "memory", CURLFORM_COPYCONTENTS, memory, CURLFORM_END); curl_formadd( &formpost, &lastptr, CURLFORM_COPYNAME, "numberofwrongtestcases", CURLFORM_COPYCONTENTS, numberofwrongtestcases, CURLFORM_END); if(CROptions::ForcePushResult) curl_formadd( &formpost, &lastptr, CURLFORM_COPYNAME, "force", CURLFORM_COPYCONTENTS, "true", CURLFORM_END); curl = curl_easy_init(); /* initalize custom header list (stating that Expect: 100-continue is not wanted */ headerlist = curl_slist_append(headerlist, buf); if(curl) { /* what URL that receives this POST */ curl_easy_setopt(curl, CURLOPT_URL, CROptions::URLToSendResults); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ContentInVar); string buffer; curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); res = curl_easy_perform(curl); char tmp[10000]; // When size was 1000, it used to throw seg faults for large CE messages. strcpy(tmp, buffer.c_str()); printf("%s\n", tmp); /* always cleanup */ curl_easy_cleanup(curl); /* then cleanup the formpost chain */ curl_formfree(formpost); /* free slist */ curl_slist_free_all (headerlist); if(CURLE_OK!=res) { //cout<<"Url to send results is "<<CROptions::URLToSendResults<<endl; sprintf(logs, "Could not send results. Curl Error code: %d\n", res); Logs::WriteLine(logs); } else { //cout<<"Url to send results is "<<CROptions::URLToSendResults<<endl; sprintf(logs, "Results sent succesfully.\n"); Logs::WriteLine(logs); } } }
PCS_API void pcs_http_form_destroy(PcsHttp handle, PcsHttpForm post) { struct http_post *formpost = (struct http_post *)post; if (formpost) { curl_formfree(formpost->formpost); pcs_free(formpost); } }
void HttpRequest::OnPostPerform(CURL* curl, bool success) { if (m_postargs != 0) curl_formfree(m_postargs); if (m_headers != 0) curl_slist_free_all(m_headers); }
bool NetDebugReport::Process() { wxDebugReportCompress::Process(); //compress files into zip wxString filename = GetCompressedFileName(); CwdGuard setCwd( wxPathOnly( filename ) ); wxLogMessage( filename ); wxStringOutputStream response; wxStringOutputStream rheader; CURL *curl_handle; curl_handle = curl_easy_init(); struct curl_slist* m_pHeaders = NULL; struct curl_httppost* m_pPostHead = NULL; struct curl_httppost* m_pPostTail = NULL; struct curl_forms testform[2]; // these header lines will overwrite/add to cURL defaults m_pHeaders = curl_slist_append(m_pHeaders, "Expect:") ; testform[0].option = CURLFORM_FILE; //we need to keep these buffers around for curl op duration wxCharBuffer filename_buffer = filename.mb_str(); testform[0].value = (const char*)filename_buffer; testform[1].option = CURLFORM_END; curl_formadd(&m_pPostHead, &m_pPostTail, CURLFORM_COPYNAME, "file", CURLFORM_ARRAY, testform, CURLFORM_END); curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, m_pHeaders); curl_easy_setopt(curl_handle, CURLOPT_URL, m_url ); // curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "SpringLobby"); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, wxcurl_stream_write); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&response); curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (void *)&rheader); curl_easy_setopt(curl_handle, CURLOPT_POST, TRUE); curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, m_pPostHead); CURLcode ret = curl_easy_perform(curl_handle); wxLogError( rheader.GetString() ); /* cleanup curl stuff */ curl_easy_cleanup(curl_handle); curl_formfree(m_pPostHead); wxString szResponse; if(ret == CURLE_OK) szResponse = wxT("SUCCESS!\n\n"); else szResponse = wxT("FAILURE!\n\n"); szResponse += wxFormat(wxT("\nResponse Code: %d\n\n") ) % ret; szResponse += rheader.GetString(); szResponse += wxT("\n\n"); szResponse += response.GetString(); szResponse += wxT("\n\n"); wxLogMessage( szResponse ); return ret == CURLE_OK; }
DWORD WINAPI Log_AutoLogging_Upload_Thread(void *vjob) { log_upload_job_t *job = (log_upload_job_t *) vjob; CURL *curl; CURLcode res; struct curl_httppost *post=NULL; struct curl_httppost *last=NULL; struct curl_slist *headers=NULL; char errorbuffer[CURL_ERROR_SIZE] = ""; curl = curl_easy_init(); headers = curl_slist_append(headers, "Content-Type: text/plain"); curl_formadd(&post, &last, CURLFORM_COPYNAME, "name", CURLFORM_COPYCONTENTS, job->player_name, CURLFORM_END); curl_formadd(&post, &last, CURLFORM_COPYNAME, "token", CURLFORM_COPYCONTENTS, job->token, CURLFORM_END); curl_formadd(&post, &last, CURLFORM_COPYNAME, "host", CURLFORM_COPYCONTENTS, job->hostname, CURLFORM_END); curl_formadd(&post, &last, CURLFORM_COPYNAME, "map", CURLFORM_COPYCONTENTS, job->mapname, CURLFORM_END); curl_formadd(&post, &last, CURLFORM_COPYNAME, "log", CURLFORM_FILE, job->filename, CURLFORM_CONTENTHEADER, headers, CURLFORM_END); curl_easy_setopt(curl, CURLOPT_HTTPPOST, post); curl_easy_setopt(curl, CURLOPT_URL, job->url); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorbuffer); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Log_Curl_Write_Void); res = curl_easy_perform(curl); /* post away! */ curl_formfree(post); curl_easy_cleanup(curl); if (res != CURLE_OK) { Com_Printf("Uploading of log failed:\n%s\n", curl_easy_strerror(res)); Com_Printf("%s\n", errorbuffer); } else { Com_Printf("Match log uploaded\n"); } Log_Upload_Job_Free(job); temp_log_upload_pending = false; return 0; }
JavaUpload::~JavaUpload() { if(isActive()) changeActive(false); delete m_plugin; curl_formfree(m_postData); m_postData = 0; }
std::string getStreamURL(std::string authToken,std::string id) { CURL *curlu; CURLcode resu; static std::string readBufferu; struct curl_httppost *formpostu = NULL; struct curl_httppost *lastptru = NULL; std::string headerTextu = "Authorization: GoogleLogin auth=" + authToken; const char *headeru = headerTextu.c_str(); struct curl_slist *headersu = NULL; headersu = curl_slist_append(headersu,headeru); curl_global_init(CURL_GLOBAL_ALL); curlu = curl_easy_init(); if (curlu) { std::string argURLu = "https://play.google.com/music/play?u=0&songid=" + id + "&pt=e"; curl_easy_setopt(curlu, CURLOPT_URL, argURLu.c_str()); curl_easy_setopt(curlu, CURLOPT_HTTPHEADER, headersu); readBufferu.clear(); curl_easy_setopt(curlu,CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curlu,CURLOPT_WRITEDATA, &readBufferu); curl_easy_setopt(curlu,CURLOPT_HTTPGET, 1); curl_easy_setopt(curlu, CURLOPT_COOKIEFILE, "cookies.dat"); resu = curl_easy_perform(curlu); /* always cleanup */ curl_easy_cleanup(curlu); curl_formfree(formpostu); } //std::cout << readBufferu << std::endl; Json::Value root; Json::Reader reader; bool parsedSuccess = reader.parse(readBufferu,root,false); const Json::Value url = root["url"]; std::string finalURL = url.asString(); boost::replace_first(finalURL, "https", "http"); return finalURL; }
int main(int argc, char *argv[]) { CURL *curl; CURLcode res; struct HttpPost *formpost=NULL; struct HttpPost *lastptr=NULL; struct curl_slist *headerlist=NULL; char buf[] = "Expect:"; /* Fill in the file upload field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "sendfile", CURLFORM_FILE, "postit2.c", CURLFORM_END); /* Fill in the filename field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "filename", CURLFORM_COPYCONTENTS, "postit2.c", CURLFORM_END); /* Fill in the submit field too, even if this is rarely needed */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "send", CURLFORM_END); curl = curl_easy_init(); /* initalize custom header list (stating that Expect: 100-continue is not wanted */ headerlist = curl_slist_append(headerlist, buf); if(curl) { /* what URL that receives this POST */ curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/examplepost.cgi"); if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) ) /* only disable 100-continue header if explicitly requested */ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); res = curl_easy_perform(curl); /* always cleanup */ curl_easy_cleanup(curl); /* then cleanup the formpost chain */ curl_formfree(formpost); /* free slist */ curl_slist_free_all (headerlist); } return 0; }