我正在尝试通过 gitlab API 和 PHP 提交到 gitlab 存储库。尽管负载对我来说看起来不错,但 cURL 请求失败并返回
[error] => branch_name is missing, commit_message is missing, actions is missing
我的代码如下所示:
$ch_git = curl_init();
curl_setopt($ch_git, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_git, CURLOPT_HTTPHEADER, array('PRIVATE-TOKEN: xxx'));
curl_setopt($ch_git, CURLOPT_URL, 'https://gitlab.com/api/v3/projects/xxx/repository/commits');
curl_setopt($ch_git, CURLOPT_POST, true);
$info = array(
'id' => 'xxx',
'branch_name' => 'master',
'commit_message' => 'updating content...',
'actions' => array(
'action' => 'update',
'file_path' => 'filename',
'content' => 'test 1234'
)
);
$payload = json_encode($info, JSON_PRETTY_PRINT);
echo '<pre>';
echo $payload;
echo '</pre>';
curl_setopt($ch_git, CURLOPT_POSTFIELDS, $payload);
$res = curl_exec($ch_git);
echo '<pre>';
print_r(json_decode($res));
echo '</pre>';
据我所见,我的有效载荷的格式与示例中的一样,但也许我遗漏了一些东西。