2014-08-28 23 views
0

我試圖找出在執行這個curl命令是怎麼回事在捲曲API調用的術語「引擎蓋下」:Curl:這個curl語句中涉及哪些API調用?

curl "http://someURL" --header "apikey:someNumbers" --header "Content-Type:audio/x-wav" 
    --header "lngCode:en_US" --data-binary @audiofile.wav 

換句話說:你是怎麼做的在C以上使用curl API?

除了將這個二進制文件發佈到遠程服務器之外,我還對如何使用curl解析來自服務器的響應(服務器分析音頻文件並將一些結果返回給客戶端)感興趣。

+0

curl.exe是開源的,所以你可以只查找自己的答案。 – 2014-08-28 02:19:44

+0

@雷米:或者我可以問一個比我有更多捲曲經驗的人,對吧? – user1884325 2014-08-28 02:20:32

回答

1

命令:

curl "http://someURL" --header "apikey:someNumbers" --header "Content-Type:audio/x-wav" --header "lngCode:en_US" --data-binary @audiofile.wav 

大致翻譯成以下的libcurl函數調用:

curl_global_init(CURL_GLOBAL_DEFAULT); 

CURL *curl = curl_easy_init(); 
curl_easy_setopt(curl, CURLOPT_URL, "http://someURL"); 

curl_slist *headers = curl_slist_append(NULL, "apikey:someNumbers"); 
curl_slist_append(headers, "Content-Type:audio/x-wav"); 
curl_slist_append(headers, "lngCode:en_US"); 
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); 

// read content of "audiofile.wav" into a memory buffer, then... 
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char*) <pointer to memory buffer>); 
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) <size of memory buffer>); 

curl_easy_perform(curl); 

curl_easy_cleanup(curl); 
curl_slist_free_all(headers); 

curl_global_cleanup(); 
+0

謝謝雷米:-) – user1884325 2014-08-28 02:49:27