将 curl 命令行转换为 php 代码



我正在尝试通过php发送此json数据,但运气不佳。

curl --header 'Authorization: Bearer <token>' -X POST https://api.site.com --header 'Content-Type: application/json' --data-binary '{"email": "mail@mail.com", "type": "note", "title": "title", "body": "Note Body"}'

这是我所拥有的:

     curl_setopt_array($ch = curl_init(), array(
      CURLOPT_HTTPHEADER => array("Authorization: Bearer <token>", "Content-Type: application/json"),
      CURLOPT_URL => "https://api.site.com",
      CURLOPT_POST => true,
      CURLOPT_BINARYTRANSFER => true,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POSTFIELDS => array(
        "email" => "mail@mail.com",
        "type" => "note",
        "title" => "alert",
        "body" => "body",
      ),
      CURLOPT_SAFE_UPLOAD => true,
    ));
    $response = curl_exec($ch);
    curl_close($ch);

尝试喜欢 CURLOPT_POSTFIELDS => json_encode( array( "email" => "mail@mail.com", "type" => "note", "title" => "alert", "body" => "body", )),

最新更新