使用https通过API添加GitLab Group


Add GitLab Group through API with https

我设法使用API v3添加一个GitLab组。现在我们把服务器从HTTP改为HTTPS,我不能再添加组了。

它在HTTP上的工作方式是

$gitPostArray = array();
$gitPostArray["name"] = $groupName;
$gitPostArray["path"] = $groupPath;
$postdata = http_build_query($gitPostArray);
$opts = array('http' =>
            array(
                'method'  => 'POST',
                'header'  => 'Content-type: application/x-www-form-urlencoded',
                'content' => $postdata
                 )
            );
$context  = stream_context_create($opts);
$result = file_get_contents($this->connectionUrl . $path . '?private_token=' . $this->private_token, false, $context);
$objPost = json_decode($result);

但是现在它不会添加我的组。我改了行:

$opts = array('http' =>
$opts = array('https' =>

编辑 2014-07-08:哦,我发现了一些有趣的东西

http://php.net/manual/en/function.stream-context-create.php # 74795和110158年http://php.net/manual/en/function.stream-context-create.php

i write

$opts = array ('https' => .....

但也可能是

 $opts = array ('ssl' => ...

编辑 2014-07-08找到了解决方案(向下滚动)https://stackoverflow.com/a/24628159/59689

你得到任何错误当你试图张贴或它失败没有任何错误?

还有,这是一个受信任的证书还是自签名的证书?

我找到解决办法了。

不使用file_get_contents你必须"fopen"一个流,然后使用stream_get_contents

工作解为:

$postdata = http_build_query($postArray);
$opts = array(
   'http' =>
       array(
       'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
         )
);
$context  = stream_context_create($opts);
$urlstream = fopen($this->connectionUrl . $path . '?private_token=' . $this->private_token, 'r', false, $context);
$result = stream_get_contents($urlstream);
$objPost = json_decode($result);