Skip to content

Commit 9cd5b75

Browse files
Hans Loosdmzoneill
authored andcommitted
fix header conversion
1 parent dc8e6fd commit 9cd5b75

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

php-binance-api.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ protected function httpRequest(string $url, string $method = "GET", array $param
11951195
}
11961196

11971197
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
1198-
$header = substr($output, 0, $header_size);
1198+
$header = $this->get_headers_from_curl_response($output);
11991199
$output = substr($output, $header_size);
12001200

12011201
curl_close($curl);
@@ -1230,6 +1230,28 @@ protected function httpRequest(string $url, string $method = "GET", array $param
12301230
return $json;
12311231
}
12321232

1233+
/**
1234+
* Converts the output of the CURL header to an array
1235+
*
1236+
* @param $response string containing the response
1237+
* @return array headers converted to an array
1238+
*/
1239+
public function get_headers_from_curl_response(string $header)
1240+
{
1241+
$headers = array();
1242+
$header_text = substr($header, 0, strpos($header, "\r\n\r\n"));
1243+
1244+
foreach (explode("\r\n", $header_text) as $i => $line)
1245+
if ($i === 0)
1246+
$headers['http_code'] = $line;
1247+
else {
1248+
list ($key, $value) = explode(': ', $line);
1249+
$headers[$key] = $value;
1250+
}
1251+
1252+
return $headers;
1253+
}
1254+
12331255
/**
12341256
* order formats the orders before sending them to the curl wrapper function
12351257
* You can call this function directly or use the helper functions

0 commit comments

Comments
 (0)