I am trying to send protocol buffer messages over HTTP using libcurl
in C++. I am POSTing in binary mode. It seems, upon posting data gets
corrupt.
Here is the code snippet:
-------------------------------
std::string st;
campaignpool.SerializeToString(&st);
//POST using curl
struct curl_slist *headers=NULL;
headers = curl_slist_append(headers, "Content-Type: application/octet-
stream");
/* post binary data */
easyhandle = curl_easy_init();
curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, &st);
curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDSIZE, st.size());
curl_easy_setopt(easyhandle, CURLOPT_HTTPHEADER, headers);
.........
.........
curl_easy_perform(easyhandle); /* post away! */
----------------------------------
Any help would be highly appreciated.
Regards,
Zia
st is a std::string. CURLOPT_POSTFIELDS need a pointer to the data
itself. See:
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPOSTFIELDS
Use:
curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, st.data());
Evan
--
Evan Jones
http://evanjones.ca/