doushun4666 2018-05-16 03:13
浏览 1658
已采纳

CURL POST请求问题,获取curl_setopt()参数警告

Tried to send the post request with XML body using CURL but constantly getting following error,

Warning: curl_setopt() expects parameter 2 to be long, string given

I'm using following CURL request,

$ch = curl_init(POST_URL);

curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($ch);
curl_close($ch);
  • 写回答

1条回答 默认 最新

  • doulaozhang0238 2018-05-16 03:56
    关注

    I think the warning is referring to the CURLOPT_MUTE option. According to the docs, CURLOPT_MUTE was removed in cURL 7.15.5:

    CURLOPT_MUTE TRUE to be completely silent with regards to the cURL functions.
    Removed in cURL 7.15.5 (You can use CURLOPT_RETURNTRANSFER instead)

    When running your code (PHP 5.5.35, reporting all errors) I get a notice:

    Notice:  Use of undefined constant CURLOPT_MUTE - assumed 'CURLOPT_MUTE' 
    

    And then a warning:

    Warning: curl_setopt() expects parameter 2 to be long, string given
    

    So it seems that PHP interprets CURLOPT_MUTE as a string, hence the warning.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?