7 #include <sys/socket.h>
21 mode m,
const std::string &post_method)
23 std::string urlp =
url_+post_method;
25 sprintf(srun,
"%d",run);
27 CURL* han = curl_easy_init();
30 XCEPT_RAISE(
evf::Exception,
"could not create handle for curlPoster");
32 struct curl_slist *headers=
NULL;
36 headers = curl_slist_append(headers,
"Content-Type: text/plain");
42 headers = curl_slist_append(headers,
"Content-Type: text/plain");
43 method =
"stacktrace";
48 headers = curl_slist_append(headers,
"Content-Type: text/plain");
54 headers = curl_slist_append(headers,
"Content-Type: application/octet-stream");
56 headers = curl_slist_append(headers,
"Expect:");
62 headers = curl_slist_append(headers,
"Content-Type: application/xml");
67 char error[CURL_ERROR_SIZE];
69 curl_easy_setopt(han, CURLOPT_URL, urlp.c_str());
71 curl_easy_setopt(han, CURLOPT_NOSIGNAL,
"");
72 curl_easy_setopt(han, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0);
74 curl_formadd(&post, &last,
75 CURLFORM_COPYNAME,
"name",
76 CURLFORM_COPYCONTENTS,
buf_->nodename, CURLFORM_END);
77 curl_formadd(&post, &last,
78 CURLFORM_COPYNAME,
"run",
79 CURLFORM_COPYCONTENTS, srun, CURLFORM_END);
80 int retval = curl_formadd(&post, &last,
81 CURLFORM_COPYNAME, method.c_str(),
82 CURLFORM_COPYCONTENTS, content,
83 CURLFORM_CONTENTSLENGTH, len,
84 CURLFORM_CONTENTHEADER, headers,
86 if(retval != 0)
std::cout <<
"Error in formadd " << retval << std::endl;
87 curl_easy_setopt(han, CURLOPT_HTTPPOST, post);
88 curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error);
90 int success = curl_easy_perform(han);
92 curl_easy_cleanup(han);
93 curl_slist_free_all(headers);
97 std::ostringstream
msg;
98 msg <<
"could not post data to url " <<
url_ <<
" error #"
99 << success <<
" " <<
error;
105 mode m,
const std::string &post_method)
108 post((
unsigned char*)content,(
unsigned int)len,run,m,post_method);
111 const std::string &post_method)
114 post(content,len,run,
bin,post_method);
121 sprintf(ps,
"run=%d",run);
122 CURL* han = curl_easy_init();
127 char error[CURL_ERROR_SIZE];
130 curl_easy_setopt(han, CURLOPT_URL,
url_.c_str() );
131 curl_easy_setopt(han, CURLOPT_POSTFIELDS,ps );
132 curl_easy_setopt(han, CURLOPT_WRITEFUNCTION, &
write_data );
133 curl_easy_setopt(han, CURLOPT_WRITEDATA, &dummy );
134 curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error );
135 int success = curl_easy_perform(han);
137 curl_easy_cleanup(han);
139 std::cout <<
"curlposter failed check" << std::endl;
void postString(const char *, size_t, unsigned int, mode, const std::string &=standard_post_method_)
void postBinary(const unsigned char *, size_t, unsigned int, const std::string &=standard_post_method_)
static const std::string standard_post_method_
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *pointer)
void post(const unsigned char *, size_t, unsigned int, mode, const std::string &)