如何将语音文件发布到Web API

时间:2018-07-03 15:11:00

标签: linux windows curl post libcurl

我正在尝试使用CURL将音频文件从VB6发布到Web api,但出现错误

  

{“成功”:false,“错误”:“未选择语音文件。”,“数据”:空}

我从vb6(SEND VOICE CALL)尝试的卷曲代码如下。 NewWave.wav文件与curl.exe位于同一目录

curl.exe --data-urlencode "caller_id=8888888888" --data-urlencode "mobile=9999999999" --data-urlencode "voice_file=@NewWave.wav" -H "authorizationkey:Bearer XgxPE1IhcwYvZxZkZ5a5FT1L9d2KxyKYhcyJAPI5iKuDNscdgIT63zf22J9qcF11" -H "cache-control:no-cache" -H "Content-Type:application/x-www-form-urlencoded" --connect-timeout 30 --request POST  "https://sms.faresms.com/api_v2/voice-call/campaign"

Web api提供程序给出了示例代码,该代码在php中

    <?php
    $curl = curl_init();

    curl_setopt_array($curl, array(
    CURLOPT_URL => "https://sms.faresms.com/api_v2/voice-call/campaign",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => "caller_id=8888888888&voice_file=2018032510455421853753553.wav&mobile=9876543210",
    CURLOPT_HTTPHEADER => array(
    "authorizationkey: Bearer XgxPE1IhcwYvZxZkZ5a5FT1L9d2KxyKYhcyJAPI5iKuDNscdgIT63zf22J9qcF11",
    "cache-control: no-cache",
    "content-type: application/x-www-form-urlencoded"),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);
    curl_close($curl);

    if ($err) {
        echo "cURL Error #:" . $err;
    } else {
        echo $response;
    }

使用VB6中的curl进行AddCallerID和VerifyCallerID的代码工作正常

对于AddCallerID

curl.exe --data-urlencode "title=MyName" --data-urlencode "mobile_no=8888888888" -H "authorizationkey:Bearer XgxPE1IhcwYvZxZkZ5a5FT1L9d2KxyKYhcyJAPI5iKuDNscdgIT63zf22J9qcF11" -H "cache-control:no-cache" -H "Content-Type:application/x-www-form-urlencoded" "https://sms.faresms.com/api_v2/voice-call/add_caller_id"

对于VerifyCallerID

curl.exe --data-urlencode "verify_otp=5892549" -H "authorizationkey:Bearer XgxPE1IhcwYvZxZkZ5a5FT1L9d2KxyKYhcyJAPI5iKuDNscdgIT63zf22J9qcF11" -H "cache-control:no-cache" -H "Content-Type:application/x-www-form-urlencoded" "https://sms.faresms.com/api_v2/voice-call/verify_caller_id/8888888888"

请指导我,以解决此问题。谢谢

0 个答案:

没有答案