Skip to content

Commit 80125c8

Browse files
authored
Update php-binance-api.php
Hello I found a bug in httpRequest method that causes error 400. It seems there is a bug that cause on some servers below error: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <TITLE>ERROR: The request could not be satisfied</TITLE> </HEAD><BODY> <H1>400 ERROR</H1> <H2>The request could not be satisfied.</H2> <HR noshade size="1px"> Bad request. <BR clear="all"> <HR noshade size="1px"> <PRE> Generated by cloudfront (CloudFront) Request ID: t5MiwWw_1St1zze5JTgwkAqVnPDc_d5ZFkGSRlYm_pK7qL8lL6izhA== </PRE> <ADDRESS> </ADDRESS> </BODY></HTML> I received this error on my server in Netherlands and with the same code, it's OK on my Germany server. It seems this error occur when httrequest method is POST. You should send your data (like order parameters) in post fields, not in url query. By the way, I edited httpRequest method and now it's work fine. I think that I solved this issue: #99
1 parent 24cddef commit 80125c8

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

php-binance-api.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,10 @@ private function httpRequest(string $url, string $method = "GET", array $params
876876
}
877877
$query = http_build_query($params, '', '&');
878878
$signature = hash_hmac('sha256', $query, $this->api_secret);
879-
$endpoint = $base . $url . '?' . $query . '&signature=' . $signature;
879+
if ($method === "POST") {
880+
$endpoint = $base . $url . '?' . 'signature=' . $signature;
881+
} else
882+
$endpoint = $base . $url . '?' . $query . '&signature=' . $signature;
880883
curl_setopt($curl, CURLOPT_URL, $endpoint);
881884
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
882885
'X-MBX-APIKEY: ' . $this->api_key,
@@ -897,7 +900,7 @@ private function httpRequest(string $url, string $method = "GET", array $params
897900
// Post and postfields
898901
if ($method === "POST") {
899902
curl_setopt($curl, CURLOPT_POST, true);
900-
// curl_setopt($curlch, CURLOPT_POSTFIELDS, $query);
903+
curl_setopt($curlch, CURLOPT_POSTFIELDS, $query);
901904
}
902905
// Delete Method
903906
if ($method === "DELETE") {

0 commit comments

Comments
 (0)