我正在嘗試從我的應用程式中發送一篇用 f3 撰寫的帖子。我遵循了這個檔案https://fatfreeframework.com/3.5/web#POST,但我不知道如何發送 JSON。在 curl 中,它是 params -d。我的 curl 呼叫是:
curl -d '{"text":"Hello.","port":[2,3],"param":[{"number":"1","text_param":["Yes"]}]}’ –H "Content-Type:application/json" http://ip.com/api/send -u usr:pass
我如何在f3中做到這一點?非常感謝。
uj5u.com熱心網友回復:
您可以使用 F3 或僅在 php 中使用 cURL 本身。由于您要求 F3,我將在下面舉一個例子。您還可以從檔案中的此鏈接了解更多資訊
F3
<?php
$options = [
'method' => 'POST',
'content' => '{"text":"Hello.","port":[2,3],"param":[{"number":"1","text_param":["Yes"]}]}',
'header' => [
'Content-Type: application/json'
'Authorization: Basic '.base64_encode('usr:pass')
]
];
$result = \Web::instance()->request('http://ip.com/api/send', $options);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/340313.html
