驾驶舱 "api/collections/save" 404 错误 PHP 卷曲
cockpit "api/collections/save" 404 error PHP curl
我正在尝试使用 PHP curl 更新 collection 中的条目,但我每次都遇到 404 错误。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, APP_URL . '/api/collections/save/trigocms?token=' . APP_TOKEN);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, ['Content-Type' => 'application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['data' => $site]));
$output = curl_exec($ch);
curl_close($ch);
$site
是一个具有这种结构的关联数组:
[
"_id" => "<identifier>"
"active" => true
"address" => "<some-value>"
"key" => "<some-value>"
]
整个条目还有几个字段,但我只想更新那 3 个字段。
添加整个条目(填充每个字段)也不起作用。
PUT
和 PATCH
方法 returns 相同的错误。
更新
经过一些调试,我发现在 /modules/Collections/Controller/RestApi.php
中的 save
方法中, $this->module('cockpit)->getUser();
returns false
和 $this->param('data', null);
returns null
出于某种未知原因。
最不解的是$this->param('data', null);
returnsnull
。
当我转储整个请求 object 时,我看到有我的 json 但未解析。只是平面 json 字符串。
经过大量调试后,我找到了解决方案。
我的错误在于卷曲。更具体地说,我试图设置 headers(愚蠢的我)的方式。
我不得不改变:
curl_setopt($ch, CURLOPT_HEADER, ['Content-Type' => 'application/json']);
至:
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
我正在尝试使用 PHP curl 更新 collection 中的条目,但我每次都遇到 404 错误。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, APP_URL . '/api/collections/save/trigocms?token=' . APP_TOKEN);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, ['Content-Type' => 'application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['data' => $site]));
$output = curl_exec($ch);
curl_close($ch);
$site
是一个具有这种结构的关联数组:
[
"_id" => "<identifier>"
"active" => true
"address" => "<some-value>"
"key" => "<some-value>"
]
整个条目还有几个字段,但我只想更新那 3 个字段。
添加整个条目(填充每个字段)也不起作用。
PUT
和 PATCH
方法 returns 相同的错误。
更新
经过一些调试,我发现在 /modules/Collections/Controller/RestApi.php
中的 save
方法中, $this->module('cockpit)->getUser();
returns false
和 $this->param('data', null);
returns null
出于某种未知原因。
最不解的是$this->param('data', null);
returnsnull
。
当我转储整个请求 object 时,我看到有我的 json 但未解析。只是平面 json 字符串。
经过大量调试后,我找到了解决方案。
我的错误在于卷曲。更具体地说,我试图设置 headers(愚蠢的我)的方式。
我不得不改变:
curl_setopt($ch, CURLOPT_HEADER, ['Content-Type' => 'application/json']);
至:
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);