• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ curl_formfree函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中curl_formfree函数的典型用法代码示例。如果您正苦于以下问题:C++ curl_formfree函数的具体用法?C++ curl_formfree怎么用?C++ curl_formfree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了curl_formfree函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: cb_get_verify_code_byurlc

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;
}
开发者ID:abitduck,项目名称:baidupcs,代码行数:60,代码来源:shell.c


示例2: testMultithreadedPoolPost

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, &copyBuffer);
  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;
}
开发者ID:Paxxi,项目名称:libmicrohttpd,代码行数:56,代码来源:test_postform.c


示例3: curl_easy_init

/********************************************************************
 *           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;
}
开发者ID:loveunk,项目名称:diseases-prediction-and-tracking,代码行数:38,代码来源:Http.cpp


示例4: AddKeyValuePair

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;
}
开发者ID:gtortone,项目名称:FzDAQ,代码行数:28,代码来源:FzHttpPost.cpp


示例5: sendFile

/**
 * 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;
}
开发者ID:xsnippet,项目名称:explorer-xsnippet,代码行数:39,代码来源:main.cpp


示例6: URL_cleanup

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);
}
开发者ID:atiti,项目名称:pam_cas-reloaded,代码行数:7,代码来源:url.c


示例7: curl_slist_append

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;
    }
}
开发者ID:zzxcv1314,项目名称:StealthDrone-Purdue-,代码行数:60,代码来源:curl_wrapper.cpp


示例8: curl_formadd

/**
 * 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;
}
开发者ID:BNUACM,项目名称:bnuoj-vjudge,代码行数:40,代码来源:LOJJudger.cpp


示例9: fetch_curl_free

/**
 * 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);
}
开发者ID:arczi84,项目名称:NetSurf-68k,代码行数:33,代码来源:curl.c


示例10: ecore_con_url_http_post_send

/**
 * 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
}
开发者ID:OpenInkpot-archive,项目名称:ecore,代码行数:32,代码来源:ecore_con_url.c


示例11: setState

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();
	}
}
开发者ID:LubosD,项目名称:fatrat,代码行数:33,代码来源:JavaUpload.cpp


示例12: curl_multi_remove_handle

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;
}
开发者ID:devmario,项目名称:http_cpp,代码行数:32,代码来源:HTTPClient.cpp


示例13: curl_formfree

/*
 * 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 */
}
开发者ID:Aviio,项目名称:curl,代码行数:33,代码来源:formdata.c


示例14: Qiniu_Io_call

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;
}
开发者ID:ThatisOK,项目名称:c-sdk,代码行数:27,代码来源:io.c


示例15: ckl_transport_free

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);
}
开发者ID:ampledata,项目名称:ckl,代码行数:7,代码来源:transport.c


示例16: curl_formfree

CPost::~CPost()
{
	if (mFormPost)
	{
		curl_formfree(mFormPost);
	}
}
开发者ID:qiu198022,项目名称:gameapi-cpp,代码行数:7,代码来源:CPost.cpp


示例17: main

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;
}
开发者ID:zhangjinde,项目名称:learn_curl,代码行数:60,代码来源:postit2.c


示例18: multi_part_curl_process

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;
}
开发者ID:coolsms,项目名称:c-sdk,代码行数:60,代码来源:coolsms.c


示例19: cleanup

/* 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;
}
开发者ID:mmoll,项目名称:patron,代码行数:32,代码来源:session_ext.c


示例20: curl_easy_cleanup

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;
	}
}
开发者ID:LubosD,项目名称:fatrat,代码行数:31,代码来源:JavaUpload.cpp



注:本文中的curl_formfree函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ curl_free函数代码示例发布时间:2022-05-30
下一篇:
C++ curl_formadd函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap