2 回答

TA貢獻2039條經(jīng)驗 獲得超8個贊
試試這個(https://incarnate.github.io/curl-to-php/):
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'url');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "recipients=xxx&originator=yyy&body=zzz");
$headers = array();
$headers[] = 'Authorization: AccessKey <key>';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);

TA貢獻2016條經(jīng)驗 獲得超9個贊
您的代碼看起來是正確的,所以我會添加一些錯誤日志來確定無響應的原因。您可以使用該curl_error()函數(shù)在為 false 時獲取錯誤$data。
// fetch remote contents
if ( false === ( $data = curl_exec( $ch ) ) ) {
// get the curl error
$error = curl_error( $ch );
var_dump( $error );
}
- 2 回答
- 0 關注
- 107 瀏覽
添加回答
舉報