Request with Post Method and CURL

1

I'm trying to retrieve data from an API on the server using CURL, however, it looks like POST data is not going

<?php

$postfields = array(
                        'login' => 'login',
                        'senha' => 'senha'
                    );

// página que receberá a requisição post
$pagina = 'http://apps.meusapps.m/api';

$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, $pagina );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $postfields );

curl_exec( $ch );

curl_close();

Return:

  

{"message": "You need to provide login and password", "status": false}

    
asked by anonymous 22.09.2017 / 20:52

1 answer

1

I do not know if after 1 year it will help you but maybe someone still has this doubt, the url probably needs an HTTP Basic Auth, so just add, just replace the $ user and $ pass variables with the tokens that are provided by the API.

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Authorization: Basic '. base64_encode($user.':'.$pass),
        'Content-Type: application/json',
           ));
    
03.10.2018 / 17:33