PHP将数据发布到cUrl,clarifai

PHP将数据发布到cUrl,clarifai,php,curl,clarifai,Php,Curl,Clarifai,我有这个卷发 curl -X POST \ -H "Authorization: Key {api-key}" \ -H "Content-Type: application/json" \ -d ' { "inputs": [ { "data": { "image": { "url": "https://samples.clarifai.com/metro-north.jpg" } } } ] }'\ https://ap

我有这个卷发

curl -X POST \
 -H "Authorization: Key {api-key}" \
 -H "Content-Type: application/json" \
 -d '
 {
"inputs": [
  {
    "data": {
      "image": {
        "url": "https://samples.clarifai.com/metro-north.jpg"
      }
    }
  }
]
}'\
https://api.clarifai.com/v2/models/aaa03c23b3724a16a56b629203edc62c/outputs
我想用PHP发出Post请求,以便获得json响应。 我试过这个:

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
     CURLOPT_HTTPAUTH => $token,
      CURLOPT_POSTFIELDS => $img_url,
    CURLOPT_URL => 'https://api.clarifai.com/v2/models/aaa03c23b3724a16a56b629203edc62c/outputs',
    CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));
但这不起作用。任何帮助都将不胜感激

错误:

array(1) { ["status"]=> array(3) { ["code"]=> int(11102) ["description"]=> string(15) "Invalid request" ["details"]=> string(28) "Malformed or invalid request" } }

“不起作用”是什么意思?您是否检索到一些错误?您似乎忘记在代码中设置
授权
内容类型
标题。至于
$img\u url
变量,当您不向我们显示内容时,我们无法判断它是否正确。您可能还需要在配置数组中添加
CURLOPT\u POST=>true
。@AlessandroMinoccheri这是我在var\u dump数组(1){[“status”]=>array(3){[“code”]=>int(11102)[“description”]=>string(15)“无效请求”[“详细信息”=>string(28)“格式错误或无效请求”}