PHP cURL 400 错误无法满足请求

PHP cURL 400 ERROR The request could not be satisfied

我将 bandsintown API 用于个人项目,我的 php 代码导致错误:

400 ERROR The request could not be satisfied. Bad Request

一些查询。我不确定为什么,并希望得到一些帮助来修复它。谢谢!

这是我现在的代码:

$ch=curl_init();

curl_setopt($ch, CURLOPT_URL, "https://rest.bandsintown.com/artists/".$artist."/events?app_id=".$app_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

$headers=array();
$headers[]="Accept: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

curl_close($ch);

这会导致相当多的艺术家出现错误,我不确定为什么。

BØRNS、MØ(通过常规 cURL 请求获得正常结果)等导致错误的一些艺术家示例

curl -X GET "https://rest.bandsintown.com/artists/B%C3%98RNS/events?app_id=$app_id" -H  "accept: application/json"

我最初认为这可能与非标准字符有关。

但让我认为这是另一个问题的是 Calvin Harris 和其他使用标准字体的类似艺术家会抛出同样的错误(而且他们在常规 cURL 请求上也能正常工作)

curl -X GET "https://rest.bandsintown.com/artists/Calvin%20Harris/events?app_id=$app_id" -H  "accept: application/json"

所以,我认为我制作 php cURL 的方式可能有问题。

如有任何帮助,我们将不胜感激。再次感谢!

可能是因为您没有对 $artist 和 $app_id 进行 urlencode。例如,space 应该用 +%20 编码,Ø%C3%98,等等。使用 urlencode(),或者如果这不起作用,请使用 rawurlencode()。