2016-04-13 134 views
0

我打電話捲曲呼叫像下面,但希望在轉換成PHP格式轉換捲曲

curl https://apis.voicebase.com/v2-beta/media \ 
--header "Authorization: Bearer $token" \ 
--form [email protected]/home/harshal/Desktop/100Hz_44100Hz_16bit_30sec.wav\ 
| tee media-post-response.json | jq '.' 

以上捲曲想convery到PHP格式像下面

set_time_limit(0); 
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 0); 
    curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 0); 
    curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 60); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300); 
    curl_setopt($ch, CURLOPT_URL, $url);     
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);  
    $result = json_decode(curl_exec($ch),TRUE); 
    curl_close($ch); 

但授權收到錯誤,但是當我傳遞參數給捲曲狀令牌& audioUrl它的工作原理。但是當傳的參數,如上面的PHP CURL_OPT

+0

什麼'$的價值header'? – Hang

+0

標題值是$ header =「Authorization:Bearer $ {token}」; –

+0

您是否檢查過PHP中的'$ token'在shell中是否具有相同的值? – Hang

回答

0

結帳的php curl official manual,它說,它不工作:

CURLOPT_HTTPHEADER 
    An array of HTTP header fields to set, in the format array('Content-type: text/plain', 'Content-length: 100') 

所以我認爲你需要改變你的$header$header = array("Authorization: Bearer ${token}")

+0

它工作。謝謝 –