Answer the question
In order to leave comments, you need to log in
Why can't I test api methods that require verification on localhost?
Hello!
I'm trying on a local server (WAMP) to test the operation of api methods that require verification (I tried to run it from a real site on a hosting - everything works there).
I am testing this exchange script https://www.livecoin.net/api/examples#php
The second example is on the link, where $url = " https://api.livecoin.net/exchange/client_orders ";
I am posting this code here
$url = "https://api.livecoin.net/exchange/client_orders";
$apiKey = "gJx7Wa7qXkPtmTAaK3ADCtr6m5rCYYMy";
$secretKey = "8eLps29wsXszNyEhOl9w8dxsOsM2lTzg";
$params = array(
'currencyPair'=> 'BTC/USD'
);
ksort($params);
$fields = http_build_query($params, '', '&');
$signature = strtoupper(hash_hmac('sha256', $fields, $secretKey));
$headers = array(
"Api-Key: $apiKey",
"Sign: $signature"
);
$ch = curl_init($url."?".$fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode!=200) {
//dump info:
echo "Status code: $statusCode, response: $response";
//throw new Exception('Can not execute the query!');
}
var_dump(json_decode($response));
Status code: 400, response: {"success":false,"errorCode":1,"errorMessage":"For authorization must specify the api kei and signature"}
Status code: 0, response: null
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "c:/wamp64/www"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp64/www/api.dev"
ServerName api.dev
<directory "c:/wamp64/www/api.dev">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
Status code: 0, response: null
Answer the question
In order to leave comments, you need to log in
The answer came from the support service - I thought they were ignoring it.
Now everything is working!
On the local host, it can be difficult to validate the certificate.
After the line
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
add the line
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question