FatFreeFramework 使用 Web 组件和方法 POST 发送 JSON
FatFreeFramework sent JSON by using Web component and method POST
我正在尝试从我用 f3 编写的应用程序发送 post。我遵循了此文档 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 中执行此操作?
非常感谢。
您可以在 php 中使用 F3 或仅使用 cURL 本身。既然你要求 F3 我会在下面举一个例子。您还可以从这里了解更多 link here in the documentation
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);
我正在尝试从我用 f3 编写的应用程序发送 post。我遵循了此文档 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 中执行此操作? 非常感谢。
您可以在 php 中使用 F3 或仅使用 cURL 本身。既然你要求 F3 我会在下面举一个例子。您还可以从这里了解更多 link here in the documentation
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);