How to send $array with the Post method in Windows?

Asked

Viewed 518 times

0

ERROR RETURNED

The GET method is not supported for this route. Supported methods: post.

MY ROUTE

Route::post('/boleto-create', function () {

        $data = array(

            'amount' => 1,
            'due_date' =>  '2019-08-03',
            'customer_document_number' => ' "1"',
            'description' => "",
            'discount_type' => '"auto"',
            'discount_limit_date' => null,
            'discount_value' => null,
            'discount_percentage' => null,
            'payer' => [
                'person_type' => 'individual',
                'name' => "Mony",
                'cnpj_cpf' => '25411417260',
                'email' =>  '[email protected]',
                'phone_number' => "",
                'zipcode' => '29090630',
                'address' => 'Rua Alan Turing',
                'neighborhood' => 'Bairro das Laranjeiras',
                'address_number' => 42,
                'address_complement' => '2o andar',
                'city_name' => 'Vitória',
                'state' => 'ES'
            ]
        );

 $client = new GuzzleHttp\Client;
        $response =  $client->request(
            'POST',
            'https://api.padmoney.com/v2/bank_billets/',
            [
                   'form_params' => [
                         $data,
                ],
                'headers'        => [

                             ],
                'decode_content' => false,
            ]
        );

        return $response->getBody()->getContents();
    });

2 answers

1

In Laravel, when a route declared as a post indicates that it will be accessible through the HTTP POST method, read more about HTTP methods here.

The framework released this exception because the route was accessed through the GET method. To access this route using the POST method use an HTTP Client such as the Postman. or an html form.

0


I DECIDED TO TRADE FORM_PARAMS FOR JSON: Route::post('/boleto-create', Function () {

        $data = array(

            'amount' => 1,
            'due_date' =>  '2019-08-03',
            'customer_document_number' => ' "1"',
            'description' => "",
            'discount_type' => '"auto"',
            'discount_limit_date' => null,
            'discount_value' => null,
            'discount_percentage' => null,
            'payer' => [
                'person_type' => 'individual',
                'name' => "Mony",
                'cnpj_cpf' => '25411417260',
                'email' =>  '[email protected]',
                'phone_number' => "",
                'zipcode' => '29090630',
                'address' => 'Rua Alan Turing',
                'neighborhood' => 'Bairro das Laranjeiras',
                'address_number' => 42,
                'address_complement' => '2o andar',
                'city_name' => 'Vitória',
                'state' => 'ES'
            ]
        );

 $client = new GuzzleHttp\Client;
        $response =  $client->request(
            'POST',
            'https://api.padmoney.com/v2/bank_billets/',
            [
                   'json' => [
                         $data,
                ],
                'headers'        => [

                             ],
                'decode_content' => false,
            ]
        );

        return $response->getBody()->getContents();
    });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.