0
我試圖實施「Changelly」 API到我的PHP的網站。我嘗試向API發出POST請求以獲取JSON文件作爲響應。我正在使用GUZZLE發出HTTP請求。POST調用「Changelly」 API返回一個HTML頁面,而不是JSON,使用PHP
這是API指南:https://changelly.com/developers#protocol
這是我的代碼:
<?php
$uri = 'http://api.changelly.com/';
//set api-key and secret
$key = '7d5dd1b8d9c748559cc7b7f31f6adc37';
$secret = 'ca7ccb683f1d6baf4c448136f0cdfa47152814dbe339aacbccbb5568fa600fbe';
//API fields and Params
$message = array();
$message['jsonrpc'] = '2.0';
$message['method'] = 'getMinAmount';
$message['params'] = array('from' => 'LTC', 'to' => 'BTC');
$message['id'] = 'test';
//serialize the message body
$data = json_encode($message);
//sign the data with the key's secret with HMAC-SHA512
$sign = hash_hmac('SHA512', $data, $secret);
echo "<br><br>".$sign."<br><br>";
//load the API call variables
//load the composer libraries
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
//intialise a guzzle client
$client = new GuzzleHttp\Client();
//create a header
$head = array('headers' => array('api-key' => $key, 'sign' => $sign, 'Content-Type' => 'application/json', 'Accept' => 'application/json'));
//execute API call
$response = $client -> post($uri, $head, $data);
$json = $response->getBody()->getContents();
//dump the result
var_dump($response);
echo '<br><br><br>';
var_dump($json);
?>
'postman' shows the same thing, am I missing something obvious here?
所以,我們您轉換HTML爲JSON不僅僅是命名您的變量JSON等? –
HTML響應是否指示任何類型的錯誤? –
@TravisActon該變量被命名爲JSON只是爲了紀念。問題在於HTML是整個Changelly主頁。我需要一個JSON響應 –