【问题标题】:How to use this POST CURL into PHP如何在 PHP 中使用这个 POST CURL
【发布时间】:2021-05-17 18:52:33
【问题描述】:
EXCLAMATION_MARK='!'
curl -X POST https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json \
--data-urlencode "From=whatsapp:$$$$$" \
--data-urlencode "Body=Hello there$EXCLAMATION_MARK" \
--data-urlencode "To=whatsapp:+$$$$$" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

大家好, 如何在 PHP 代码中使用此 curl 代码? 我已经尝试了很多选择,但没有成功

【问题讨论】:

  • 也许incarnate.github.io/curl-to-php 应该有帮助
  • 如果您展示您尝试过的一些选项以及您在尝试这些选项时遇到的任何错误,人们将能够更好地帮助您

标签: php curl post


【解决方案1】:

你会做类似的事情。

$TWILIO_ACCOUNT_SID="whatever";
$TWILIO_AUTH_TOKEN="FLEH";
$ch = curl_init("https://api.twilio.com/2010-04-01/Accounts/{$TWILIO_ACCOUNT_SID}/Messages.json");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,array(
    "From"=>"whatsapp:\$\$\$\$\$",
    "Body"=>"Hello there!",
    "To"=>"whatsapp:+\$\$\$\$\$"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN");
$response = curl_exec($ch);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-10
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 2015-10-21
    • 2023-01-15
    • 1970-01-01
    • 2017-05-25
    相关资源
    最近更新 更多