0

我们正在尝试发布到需要在其中一个键中包含“POST 对象”的 REST API 端点。在 javascript/jquery 中,这很好用。但是,在 PHP 中使用 CURL,端点不会在此处接收对象(称为“组件”):

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_URL, 'http://api.sitesitesite.com');

    $comps = array('slug' => "xyz",
                   'visble' => 1,
                   'color' => "xyz",
                   'shape' => "xyz",
                   'version' => "2",
            );

    $post_args = array();
    $post_args['components'] = $comps;
    $post_args['id'] = $id;

    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_args);

    $result = curl_exec($ch);

    $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
4

1 回答 1

2

摆脱“CURLOPT_CUSTOMREQUEST”并使用“CURLOPT_POST”

curl_setopt($ch, CURLOPT_POST, true);
于 2013-03-19T22:08:40.020 回答