gpt4 book ai didi

php - 将新主题和文件发布到 Brightsapce API 时出现错误 400

转载 作者:搜寻专家 更新时间:2023-10-31 21:19:33 25 4
gpt4 key购买 nike

将 PHP 与 guzzle 结合使用 我正在尝试根据 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);

一切看起来都按照文档工作,但我总是收到“请求缺少或无效参数”我看不到我可能缺少什么参数?

最佳答案

这是通过将“content-type”大写来解决的

关于php - 将新主题和文件发布到 Brightsapce API 时出现错误 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56519486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com