Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 向Brightsapce API发布新主题和文件时出现错误400_Php_Guzzle_Desire2learn_Valence - Fatal编程技术网

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

Php 向Brightsapce API发布新主题和文件时出现错误400,php,guzzle,desire2learn,valence,Php,Guzzle,Desire2learn,Valence,使用带有guzzle的PHP,我试图将一个带有文件的新主题发布到Brightsapce API中,如下所示 使用guzzle streams,我构建了如下所示的请求 --xxBOUNDARYxx content-type: application/json Content-Disposition: form-data; name="" Content-Length: 223 {"Title":"Placeholder, Please Delete","ShortTitle":"","

使用带有guzzle的PHP,我试图将一个带有文件的新主题发布到Brightsapce API中,如下所示

使用guzzle streams,我构建了如下所示的请求

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