gpt4 book ai didi

php file_get_contents($url) & 变成 &

转载 作者:可可西里 更新时间:2023-11-01 12:36:58 28 4
gpt4 key购买 nike

我正在尝试像这样向 coinbase api 发出请求

$url = "https://api.gdax.com/products/BTC-USD/candles?start=".date($format,$starting_date)."&end=".date($format,$ending_date)."&granularity=".$granularity;

然后我在 file_get_contents($url) 中传递它,但它给了我一个错误

file_get_contents(https://api.gdax.com/products/BTC-USD/candles?start=2015-05-07&end=2015-05-08&granularity=900) : 无法打开流:HTTP 请求失败! HTTP/1.1 400 错误请求。

问题当然是什么时候“&”变成了“&”。

最佳答案

发布这个是因为它最适合我。我知道这是一个老问题。

我发现在使用 http_build_query 构建查询时,& 符号问题消失了。

例子

$url = 'https://example.url';

// http_build_query builds the query from an array
$query_array = array (
'search' => $string,
'from' => $from,
'to' => $to,
'format' => 'json'
);

$query = http_build_query($query_array);
$result = file_get_contents($url . '?' . $query);

编辑:刚看到@joshi 的回答(实际上是点击了链接),那里使用了 http_build_query。

关于php file_get_contents($url) & 变成 &,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30120211/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com