Home > Software engineering >  FatFreeFramework sent JSON by using Web component and method POST
FatFreeFramework sent JSON by using Web component and method POST

Time:10-26

I'm trying to send a post from my app written in f3. I followed this documentation https://fatfreeframework.com/3.5/web#POST, but I don't know how to send JSON. In curl it is params -d. My call by curl is:

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

How do I do it in f3? Thanks a lot.

CodePudding user response:

You can use F3 or just use cURL itself in php. Since you asked for F3 I'll put an example below. You can also learn more from this 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);
  • Related