繁体   English   中英

如何在PHP中传递此cURL?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM