使用Nextcloud/owncloud API的cURL PUT请求 [英] cURL PUT Request with Nextcloud / owncloud API

查看:1061
本文介绍了使用Nextcloud/owncloud API的cURL PUT请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过他们的API更新现有的Nextcloud用户.当我直接通过外壳执行此操作时

I tried to update an existing Nextcloud user through their API. When I do it directly via shell it works

curl -u user:pass -X PUT "https://example.org/ocs/v1.php/cloud/users/admin" -H "OCS-APIRequest: true" -d key="quota" -d value="5GB"

但是当我尝试使用以下代码通过PHP进行操作时,它总是返回失败997"

But when I try to do it via PHP with the following code it always returns "failure 997"

$url = 'https://' . $ownAdminname . ':' . $ownAdminpassword . '@example.org/ocs/v1.php/cloud/users/admin';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$fields = array("quota" => "5GB");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'OCS-APIRequest: true'
    ));
$response = curl_exec($ch);
curl_close($ch);
echo "Response: ".$response;

推荐答案

cURL命令和您粘贴的PHP代码之间的区别在于

The difference between the cURL command and the PHP code you pasted lies in a poorly designed user provisioning API.

使用以下cURL参数:

Using these cURL arguments:

-d key="quota" -d value="5GB"

...不等同于您要发布的字段:

... is not equivalent to the fields you're posting:

$fields = array("quota" => "5GB");

...而是:

$fields = array(
    'key' => 'quota',
    'value' => '5GB',
);

有关获取的997代码的说明,可以在key" ($parameters['_put']['key']将评估为null),因此会出现错误.

The explanation for the 997 code you're getting can be found in https://github.com/owncloud/core/blob/v10.0.3/apps/provisioning_api/lib/Users.php#L269-L272: since there's no "key" key in the data submitted ($parameters['_put']['key'] will evaluate as null) and hence the error.

这篇关于使用Nextcloud/owncloud API的cURL PUT请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆