本文整理汇总了C++中curl_formadd函数的典型用法代码示例。如果您正苦于以下问题:C++ curl_formadd函数的具体用法?C++ curl_formadd怎么用?C++ curl_formadd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_formadd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: backend_log
CURLcode backend_log(char * middleware, char * uuid, struct timeval tv, float value) {
CURL *curl;
CURLcode res;
char url[255], useragent[255], post[255];
sprintf(url, "%s/data/%s.json", middleware, uuid); /* build url */
sprintf(useragent, "vzlogger/%s (%s)", VZ_VERSION, curl_version());
sprintf(post, "?timestamp=%lu%lu&value=%f", tv.tv_sec, tv.tv_usec, value);
curl_global_init(CURL_GLOBAL_ALL);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "value",
CURLFORM_PTRCONTENTS , value_str,
CURLFORM_END);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "timestamp",
CURLFORM_PTRCONTENTS , ×tamp,
CURLFORM_END);
curl = curl_easy_init();
if (curl) {
/* what URL that receives this POST */
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_setopt(curl, CURLOPT_USERAGENT, useragent);
curl_easy_setopt(curl, CURLOPT_VERBOSE, (int) opt.verbose);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl); /* always cleanup */
curl_formfree(formpost); /* then cleanup the formpost chain */
return res;
}
return -1;
}
示例2: ov_curl_set_string
/* CURL Add in a string parameter */
int ov_curl_set_string(void *ov_msg_handle, const char *name, char *val)
{
ov_msg_t *ov_msg = (ov_msg_t*) ov_msg_handle;
assert(ov_msg->magic_no == OV_MSG_MAGIC_NO);
printf("SET MULTIPART ENTRY: NAME = '%s' VAL = '%s'\n", name, val);
curl_formadd(&ov_msg->formpost, &ov_msg->lastptr, CURLFORM_COPYNAME, name, CURLFORM_COPYCONTENTS, val, CURLFORM_END);
return 0;
}
示例3: formadd_files
static int formadd_files(VALUE data_key, VALUE data_value, VALUE self) {
struct curl_state *state = get_curl_state(self);
VALUE name = rb_obj_as_string(data_key);
VALUE value = rb_obj_as_string(data_value);
curl_formadd(&state->post, &state->last, CURLFORM_PTRNAME, RSTRING_PTR(name),
CURLFORM_FILE, RSTRING_PTR(value), CURLFORM_END);
return 0;
}
示例4: throw
bool HTTP::POSTFile(std::string url, std::string filePath, std::string& output) throw (InputException) {
char errorBuffer[CURL_ERROR_SIZE];
std::string http_code;
std::string redirect = url;
char *ct = NULL;
// wait for timeout
wait();
// error detection
CURLcode result;
//open connection
CURL * curlPost = curl_easy_init();
struct curl_httppost *post = NULL;
struct curl_httppost *last = NULL;
if (curlPost) {
curl_formadd(&post, &last, CURLFORM_COPYNAME, "file", CURLFORM_FILE, filePath.c_str(), CURLFORM_END);
//Specify the API Endpoint
curl_easy_setopt(curlPost, CURLOPT_URL, url.c_str());
//Specify the HTTP Method
result = curl_easy_setopt(curlPost, CURLOPT_HTTPPOST, post);
// curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
// curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
// curl_easy_setopt(curl, CURLOPT_HEADER, 1);
// /**
// * Post Redirection - if we cant set this, the next redir is GET method
// 0 -> do not set any behavior
// 1 -> follow redirect with the same type of request only for 301 redirects.
// 2 -> follow redirect with the same type of request only for 302 redirects.
// 3 -> follow redirect with the same type of request both for 301 and 302 redirects.*/
// curl_easy_setopt(curl, CURLOPT_POSTREDIR, 3);
//
curl_easy_setopt(curlPost, CURLOPT_WRITEFUNCTION, &writeText);
curl_easy_setopt(curlPost, CURLOPT_WRITEDATA, &output);
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
// send request
result = curl_easy_perform(curlPost);
// clean
curl_easy_cleanup(curlPost);
// exception on request error
if (result != CURLE_OK) {
InputException e("HTTP POST File: Curl Error: " + std::string(errorBuffer));
throw e;
}
}
curl_formfree(post);
return true;
}
示例5: curlization
int curlization(char *uri) {
int ret=0;
buf->size=0;
curl_easy_setopt(curl, CURLOPT_USERAGENT, UserAgent);
curl_easy_setopt(curl, CURLOPT_URL, uri);
#ifdef HEADFUNC
bufhead->size=0;
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, head_callback);
#else
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
#endif
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf);
//можно так
#ifdef FORMPOST
curl_formadd(&post, &last, CURLFORM_COPYNAME, "hash",CURLFORM_PTRCONTENTS, "aaaaaaaaaaaa", CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "hash2",CURLFORM_PTRCONTENTS, "bbbbbbbbbbbbb", CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "hash3",CURLFORM_PTRCONTENTS, "cccccccccccccccc", CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
#else
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, Post);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, sizeof(Post)-1);
#endif
if (curl_easy_perform(curl) != CURLE_OK) {
fprintf(stderr, "%s: %s\n\n", uri, (error[0]) ? error : "Unknown Error");
ret=-1;
}
curl_easy_cleanup(curl);
#ifdef FORMPOST
curl_formfree(post);
#endif
return ret;
}
示例6: curlUpload
static optional<string> curlUpload(const char* path, const char* url) {
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
curl_global_init(CURL_GLOBAL_ALL);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "fileToUpload",
CURLFORM_FILE, path,
CURLFORM_END);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "submit",
CURLFORM_COPYCONTENTS, "send",
CURLFORM_END);
if(CURL* curl = curl_easy_init()) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, dataFun);
string ret;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ret);
/* what URL that receives this POST */
curl_easy_setopt(curl, CURLOPT_URL, escapeUrl(url).c_str());
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
// Internal CURL progressmeter must be disabled if we provide our own callback
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false);
// Install the callback function
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressFunction);
CURLcode res = curl_easy_perform(curl);
if(res != CURLE_OK)
ret = string("Upload failed: ") + curl_easy_strerror(res);
curl_easy_cleanup(curl);
curl_formfree(formpost);
if (!ret.empty())
return ret;
else
return none;
} else
return string("Failed to initialize libcurl");
}
示例7: curl_formadd
void HttpRequest::AddFile(const std::string& name, const std::string& localfilename,
const std::string& contenttype, const std::string& filename)
{
curl_formadd(&m_postargs, &m_postargslast,
CURLFORM_COPYNAME, name.c_str(),
CURLFORM_FILE, localfilename.c_str(),
CURLFORM_CONTENTTYPE, contenttype.c_str(),
CURLFORM_END);
m_upload = true;
}
示例8: sendChatAction
void sendChatAction(int chat_id, string action)
{
string URL = BOTAPI + "sendChatAction";
// ============ convert string to char array =========== //
char c[200];
strncpy(c, URL.c_str(), sizeof(c));
c[sizeof(c) - 1] = 0;
FILE *fp;
CURL *curl = init(c, "sendChatAction.json", fp);
// ============ add fields =========== //
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "chat_id", CURLFORM_COPYCONTENTS, to_string(chat_id).c_str(), CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "action", CURLFORM_COPYCONTENTS, action.c_str(), CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
formpost = NULL;
lastptr = NULL;
fclose(fp);
}
示例9: init_curl
void engine::attach(std::string server,
const std::string& key,
const std::string& file,
const std::string& filename,
int chunk_id,
int num_chunks,
report_level s,
validate_cert v)
{
init_curl(key, s, v);
server += "/attachments";
curl_easy_setopt(m_curl, CURLOPT_URL, server.c_str());
struct curl_httppost* formpost = NULL;
struct curl_httppost* lastptr = NULL;
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "Filedata",
CURLFORM_FILE, file.c_str(),
CURLFORM_END);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "name",
CURLFORM_COPYCONTENTS, filename.c_str(),
CURLFORM_END);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "chunk",
CURLFORM_COPYCONTENTS, base::to_string(chunk_id).c_str(),
CURLFORM_END);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "chunks",
CURLFORM_COPYCONTENTS, base::to_string(num_chunks).c_str(),
CURLFORM_END);
curl_form_guard fg(formpost);
curl_easy_setopt(m_curl, CURLOPT_HTTPPOST, formpost);
if (s >= NORMAL) {
io::mout << "Uploading chunk '" << file << "'." << io::endl;
}
process_attach_chunk_responce(perform(), s);
}
示例10: setWebhook
void setWebhook(string url, string certificate)
{
string URL = BOTAPI + "setWebhook";
// ============ convert string to char array =========== //
char c[200];
strncpy(c, URL.c_str(), sizeof(c));
c[sizeof(c) - 1] = 0;
FILE *fp;
CURL *curl = init(c, "setWebhook.json", fp);
// ============ add fields =========== //
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "url", CURLFORM_COPYCONTENTS, url.c_str(), CURLFORM_END);
if (certificate != "")
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "certificate", CURLFORM_FILE, certificate.c_str(), CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
formpost = NULL;
lastptr = NULL;
fclose(fp);
}
示例11: getUpdates
void getUpdates(int offset, int limit, int timeout)
{
string URL = BOTAPI + "getUpdates";
// ============ convert string to char array =========== //
char c[200];
strncpy(c, URL.c_str(), sizeof(c));
c[sizeof(c) - 1] = 0;
FILE *fp;
CURL *curl = init(c, "getUpdates.json", fp);
// ============ add fields =========== //
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "offset", CURLFORM_COPYCONTENTS, to_string(offset).c_str(), CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "limit", CURLFORM_COPYCONTENTS, to_string(limit).c_str(), CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "timeout", CURLFORM_COPYCONTENTS, to_string(timeout).c_str(), CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
formpost = NULL;
lastptr = NULL;
fclose(fp);
}
示例12: curl_formadd
void FZHttpPost::AddKeyValuePair(const std::string& key, const std::string& value)
{
// Add a key-value pair to the POST
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, key.data(),
CURLFORM_COPYCONTENTS, value.data(),
CURLFORM_END);
// increment number of key-value pairs in post
++fPostPairs;
}
示例13: forwardMessage
void forwardMessage(int chat_id, int from_chat_id, int message_id)
{
string URL = BOTAPI + "forwardMessage";
// ============ convert string to char array =========== //
char c[200];
strncpy(c, URL.c_str(), sizeof(c));
c[sizeof(c) - 1] = 0;
FILE *fp;
CURL *curl = init(c, "forwardMessage.json", fp);
// ============ add fields =========== //
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "chat_id", CURLFORM_COPYCONTENTS, to_string(chat_id).c_str(), CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "from_chat_id", CURLFORM_COPYCONTENTS, to_string(from_chat_id).c_str(), CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "message_id", CURLFORM_COPYCONTENTS, to_string(message_id).c_str(), CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
formpost = NULL;
lastptr = NULL;
fclose(fp);
}
示例14: curl_formadd
void HttpFormRequest::addBinary(const std::string &key, const std::vector<char> &data) {
std::cout << "ttpFormRequest::addBinary(): " << data.data() << "\t" << data.size() << std::endl;
curl_formadd(
&_formPost,
&_lastPost,
CURLFORM_COPYNAME, key.c_str(),
CURLFORM_BUFFER, key.c_str(),
CURLFORM_BUFFERPTR, data.data(),
CURLFORM_BUFFERLENGTH, data.size(),
CURLFORM_END);
}
示例15: Qiniu_Io_PutFile
Qiniu_Error Qiniu_Io_PutFile(
Qiniu_Client* self, Qiniu_Io_PutRet* ret,
const char* uptoken, const char* key, const char* localFile, Qiniu_Io_PutExtra* extra)
{
Qiniu_Io_form form;
Qiniu_Io_form_init(&form, uptoken, key, extra);
curl_formadd(
&form.formpost, &form.lastptr, CURLFORM_COPYNAME, "file", CURLFORM_FILE, localFile, CURLFORM_END);
return Qiniu_Io_call(self, ret, form.formpost);
}