Request with Post and CURL Method

Asked

Viewed 1,625 times

1

I am trying to recover the data from an API on the server using CURL, however it seems that 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 data","status":false}

1 answer

1

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

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

Browser other questions tagged

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