将新主题和文件发布到 Brightsapce 时出现错误 400 API
Error 400 when posting a new topic and file to Brightsapce API
使用 PHP 和 guzzle 我正在尝试 post 根据 https://docs.valence.desire2learn.com/res/content.html#post--d2l-api-le-(version)-(orgUnitId)-content-modules-(moduleId)-structure-
将文件添加到 Brightsapce API 的新主题
我使用 guzzle 流构建了如下所示的请求。
--xxBOUNDARYxx
content-type: application/json
Content-Disposition: form-data; name=""
Content-Length: 223
{"Title":"Placeholder, Please Delete","ShortTitle":"","Type":1,"TopicType":1,"Url":"\/content\/enforced\/376743-TKS101_TRI-3_2014\/test.html","StartDate":null,"EndDate":null,"DueDate":null,"IsHidden":false,"IsLocked":false}
--xxBOUNDARYxx
content-type: text/html
Content-Disposition: form-data; name=""; filename="test.html"
Content-Length: 477
<!DOCTYPE html>
<!--
...
$multipart_mixed = [
[
'name' => "",
'headers' => [
'content-type' => "application/json",
],
'contents' => json_encode($contentObjectData->toArray())
],
[
'name' => "",
'headers' => [
'content-type' => mime_content_type($file),
'Content-Disposition' => "form-data; name=\"\"; filename=\"$fileName\""
],
'contents' => file_get_contents($file)
]
];
$headers = ['Content-Type' => 'multipart/mixed;boundary=xxBOUNDARYxx'];
$body = new MultipartStream($multipart_mixed, $boundary);
$uri = $this->valenceInstance->authenticateUri("/d2l/api/le/$this->le_version/$orgUnitId/content/modules/$moduleId/structure/?base64=false", "POST");
return new Request("POST", $uri, $headers, $body);
一切看起来都按照文档工作,但我总是收到 "Request has missing or invalid parameters"
我看不到我可能缺少什么参数?
这是通过大写 "content-type"
解决的
使用 PHP 和 guzzle 我正在尝试 post 根据 https://docs.valence.desire2learn.com/res/content.html#post--d2l-api-le-(version)-(orgUnitId)-content-modules-(moduleId)-structure-
将文件添加到 Brightsapce API 的新主题我使用 guzzle 流构建了如下所示的请求。
--xxBOUNDARYxx
content-type: application/json
Content-Disposition: form-data; name=""
Content-Length: 223
{"Title":"Placeholder, Please Delete","ShortTitle":"","Type":1,"TopicType":1,"Url":"\/content\/enforced\/376743-TKS101_TRI-3_2014\/test.html","StartDate":null,"EndDate":null,"DueDate":null,"IsHidden":false,"IsLocked":false}
--xxBOUNDARYxx
content-type: text/html
Content-Disposition: form-data; name=""; filename="test.html"
Content-Length: 477
<!DOCTYPE html>
<!--
...
$multipart_mixed = [
[
'name' => "",
'headers' => [
'content-type' => "application/json",
],
'contents' => json_encode($contentObjectData->toArray())
],
[
'name' => "",
'headers' => [
'content-type' => mime_content_type($file),
'Content-Disposition' => "form-data; name=\"\"; filename=\"$fileName\""
],
'contents' => file_get_contents($file)
]
];
$headers = ['Content-Type' => 'multipart/mixed;boundary=xxBOUNDARYxx'];
$body = new MultipartStream($multipart_mixed, $boundary);
$uri = $this->valenceInstance->authenticateUri("/d2l/api/le/$this->le_version/$orgUnitId/content/modules/$moduleId/structure/?base64=false", "POST");
return new Request("POST", $uri, $headers, $body);
一切看起来都按照文档工作,但我总是收到 "Request has missing or invalid parameters" 我看不到我可能缺少什么参数?
这是通过大写 "content-type"
解决的