반응형
#include <iostream>
#include <string>
#include <curl/curl.h>
#include <fstream>
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
int main(void)
{
std::string contents;
std::ifstream in("test2.wav", std::ios::in | std::ios::binary);
if (in)
{
in.seekg(0, std::ios::end);
contents.resize(in.tellg());
in.seekg(0, std::ios::beg);
in.read(&contents[0], contents.size());
in.close();
}
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);
curl = curl_easy_init();
headerlist = curl_slist_append(headerlist, buf);
if (curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: audio/wav");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POST,1);
curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:9080");
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, contents.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, contents.data());
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
curl_slist_free_all(headerlist);
}
return 0;
}
반응형
'BackEnd FrontEnd > C , C++' 카테고리의 다른 글
arm cross compile 시 curl negative size error 발생하는 경우 (0) | 2019.12.18 |
---|---|
C/C++ curl로 메일보내기 예제 (0) | 2019.10.30 |
[C] curl 로 pcm 파일 전달하기 (0) | 2019.10.23 |
openssl 사용하여 개발하기 전 설치할 것 -lssl (0) | 2019.07.29 |
restbed github 오픈소스 사용 (0) | 2018.06.28 |