0

I want to build a client API, and the server documentation says :

DEFINITION
GET https://api.mybitx.com/api/1/balance
EXAMPLE REQUEST
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/balance

here's my code :

<?
require_once('../config.php');

$post = [
    'keyid' => $api_key,
    'keysecret' => $api_secret
];

$ch = curl_init('https://api.mybitx.com/api/1/balance');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>

it gives me :

string(19) "Method Not Allowed "

but when I run :

$ curl -u *****:***** https://api.mybitx.com/api/1/balance

from SSH terminal, it gives me correct result. what's wrong with my PHP Curl code?

thank you

Saint Robson
  • 5,475
  • 18
  • 71
  • 118
  • 1
    `-u keyid:keysecret` is not `CURLOPT_POSTFIELDS`. Try `curl_setopt($ch, CURLOPT_USERPWD, $api_key . ":" . $api_secret);` instead. – Roland Starke Dec 10 '17 at 15:25
  • @RolandStarke : thank you for your comment, bro. but I'm a beginner in this PHP-CURL, could you please give me some documentation that I can read more details. – Saint Robson Dec 10 '17 at 15:27
  • 1
    @SaintRobson take a look at this: https://stackoverflow.com/questions/2140419/how-do-i-make-a-request-using-http-basic-authentication-with-php-curl – Gino Pane Dec 10 '17 at 15:32
  • @GinoPane : thank you, bro!! it works now... – Saint Robson Dec 10 '17 at 15:35

0 Answers0