向Brightsapce API发布新主题和文件时出现错误400

时间:2019-06-10 01:02:02

标签: php guzzle desire2learn valence

使用PHP时,我尝试按照https://docs.valence.desire2learn.com/res/content.html#post--d2l-api-le-(version)-(orgUnitId)-content-modules-(moduleId)-structure-

将带有文件的新主题发布到Brightsapce API中

使用狂饮流,我建立了看起来像这样的请求。

--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);

一切似乎都按文档要求进行,但我总是收到“请求缺少参数或参数无效”的信息 我看不到我可能缺少的参数?

1 个答案:

答案 0 :(得分:1)

此问题通过将“内容类型”大写来解决