FILE *fp;
long lSize;
char *buffer;
fp = fopen ( "record.pcm" , "rb" );
if( !fp ) perror("record.pcm"),exit(1);
fseek( fp , 0L , SEEK_END);
lSize = ftell( fp );
rewind( fp );
/* allocate memory for entire content */
buffer = ( char *)calloc( 1, lSize+1 );
if( !buffer ) fclose(fp),fputs("memory alloc fails",stderr),exit(1);
/* copy the file into the buffer */
if( 1!=fread( buffer , lSize, 1 , fp) )
fclose(fp),free(buffer),fputs("entire read fails",stderr),exit(1);
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:8080");
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE,lSize);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buffer);
//curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
//curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
//curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
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_formfree(formpost);
curl_slist_free_all(headerlist);
}
/* do your work here, buffer is a string contains the whole text */
fclose(fp);
free(buffer);
'BackEnd FrontEnd > C , C++' 카테고리의 다른 글
arm cross compile 시 curl negative size error 발생하는 경우 (0) | 2019.12.18 |
---|---|
C/C++ curl로 메일보내기 예제 (0) | 2019.10.30 |
c++ : send wav data with curl (0) | 2019.10.03 |
openssl 사용하여 개발하기 전 설치할 것 -lssl (0) | 2019.07.29 |
restbed github 오픈소스 사용 (0) | 2018.06.28 |