Thanks for stopping by !
【背景】
相同接口,使用 GET 方式,若直接从浏览器(Firefox 或 chrome)直接访问,返回值中的C字段,返回值为0.087966554。
当使用 curl方式 请求,C字段返回值为0。
【解决方法】
使用 GuzzleHttp\Client 方法,如下:
private function requestApi($url)
{
$client = new Client();
$response = $client->get($url);
if ($response->getStatusCode() == 200) {
return $response->getBody()->getContents();
} else {
return [];
}
}
【为什么 curl 会将 float 转为 int ?】
尚未找到原因。
致谢:https://stackoverflow.com/questions/959063/how-to-send-a-get-request-from-php/55618645#55618645?newreg=dfc597b9993d472bb8e8af51f19871b6 感谢 Mark Baaijens 的解决方案。