【发布时间】:2020-09-11 19:21:26
【问题描述】:
我在发送到 API 的 POST 请求时遇到了一些问题。
API 是这样说的:
API 让您可以通过发送 HTTP POST 请求来创建新的网络研讨会 https://clevercast.com/api/v1/webinar/create 该请求需要基本身份验证,使用 Clevercast 用户的电子邮件地址 必要的权限和他的密码。 请求必须编码为 Multipart 表单。必须设置“Content-Type”标头 到“多部分/表单数据”。它的正文应包含必填字段,其字符串值来自 下表
于是转头写了如下代码:
/* API URL */
$url = 'https://clevercast.com/api/v1/webinar/create';
$username = 'username';
$password = 'password';
/* Init cURL resource */
$ch = curl_init($url);
/* Array Parameter Data */
$data = ['name'=>'Begrafenis van xxxx', 'language'=>'fr', 'start_time'=> '2020-28-12
13:05', 'end_time'=>'2020-28-12
13:30'];
/* pass encoded JSON string to the POST fields */
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
/* set the content type json */
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: ‘multipart/form-data'));
/* set return type json */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//get info
/* execute request */
$result = curl_exec($ch);
/* close cURL resource */
curl_close($ch);
print_r($result);
但我总是得到 404 回复。
API 的人也给我发了一个示例代码。它应该是这样的:
curl --request POST -u "username:password" -k "https://app.clevercast.com/api/v1/webinar/create/" -F name="Afscheid van XXX" -F language="nl" -F logo=@/data/funerarium-logo。 png -F logo_link="https://example.com/my-funerarium/" -F poster=@/data/foto-overledene.jpg -F start_time="2020-08-04 14:00" -F end_time= "2020-08-04 15:00" -F live_private_communication="questions" -F vod_private_communication="questions" -F email_questions="familie@example.com" -F sender_name="My Funerarium" -F reply_to_email="info@ my-funerarium.com" -F reply_to_name="My Funerarium" -F description="Wij zijn heel verdrietig dat XXX plotseling is ingeslapen. Wij zullen altijd van je blijven houden.
Via de tab hernaast kan u een bericht achterlaten voor德纳贝斯坦登。” -F background_color="rgba(8,97,106,1)" -F panel_text_color="rgba(8,97,106,1)"
有人知道问题出在哪里吗?有没有办法只发送 RAW curl 命令?
【问题讨论】:
-
不确定是否重要,但他们的示例末尾有一个
/-webinar/create/" -
示例 curl 命令中的字段是可选的还是必需的?
-
该人发送给您的 URL 与您使用的不同。它以
app.https://app.clevercast.com/api/v1/webinar/create/开头,您使用的是https://clevercast.com/api/v1/webinar/create尝试复制/粘贴确切的URL -
感谢您的关注。现在我得到一个内部错误,而不是 404 错误了。为了回复 RamRaider,我在代码中输入的字段是必填字段。