[英]How to pass this cURL in PHP?
我從IBM Watson演講中得到了這個文本文件,以發送音頻文件進行處理:
curl -X POST -u <username>:<password>
--header "Content-Type: audio/flac"
--header "Transfer-Encoding: chunked"
--data-binary @<path>0001.flac
"https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true"
但是我應該如何將其構建到PHP cURL中呢? 像這樣嗎
$headr = array();
$headr[] = 'Content-Type: audio/flac';
$headr[] = 'Transfer-Encoding: chunked';
...
$crl = curl_init('https://stream.watsonplatform.net/speech-to-text/api');
curl_setopt($crl, CURLOPT_POST, 1);
curl_setopt($crl, CURLOPT_POSTFIELDS, array("username:password"=>"myuser:mypassword","data-binary"=>"@<path>0001.flac"));
curl_setopt($crl, CURLOPT_HTTPHEADER, $headr);
那-x和-u呢?
執行此操作時-X POST已設置
curl_setopt($crl, CURLOPT_POST, 1);
至於-u,您可以使用它,不要在post字段數組中包含username:password。
curl_setopt($crl, CURLOPT_USERPWD, "yourusername:yourpassword");
對於使用--data-binary,已經有一個關於如何使用php curl實現它的stackoverflow帖子: cURL中的data-binary參數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.