【问题标题】:FatFreeFramework sent JSON by using Web component and method POSTFat Free Framework 使用 Web 组件和方法 POST 发送 JSON
【发布时间】:2021-12-11 03:17:25
【问题描述】:

我正在尝试从我用 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 中做到这一点? 非常感谢。

【问题讨论】:

    标签: php json post fat-free-framework


    【解决方案1】:

    您可以使用 F3 或仅在 php 中使用 cURL 本身。既然您要求 F3,我将在下面举一个例子。您还可以通过此链接了解更多信息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);
    

    【讨论】:

    • 非常感谢,在将您的解决方案与我的解决方案进行比较后,我发现我放错了方法选项并将其放入标题数组中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多