PHP cURL 400错误无法满足请求

PHP cURL 400错误无法满足请求,php,api,curl,php-curl,Php,Api,Curl,Php Curl,我将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=".$a

我将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Ø(通过常规卷曲请求获得正常结果)

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

但让我觉得这是另一个问题的是,卡尔文·哈里斯和其他类似的标准字体艺术家也犯了同样的错误(而且他们在常规卷曲要求下也能很好地工作)

因此,我认为我制作php卷曲的方式可能有问题


任何帮助都将不胜感激。再次感谢

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

非常感谢。我已经尝试过urlencode,因为我认为这可能是BØRNS类艺术家的问题,但没有成功。rawurlencode做到了这一点。@pokemonjello嗯,严格地说,urlencode()不遵循规范,而rawurlencode严格按照规范进行编码(规范说
将空格编码为%20
,但出于某种原因,大多数人/服务使用
+
而不是空格)
curl -X GET "https://rest.bandsintown.com/artists/B%C3%98RNS/events?app_id=$app_id" -H  "accept: application/json"
curl -X GET "https://rest.bandsintown.com/artists/Calvin%20Harris/events?app_id=$app_id" -H  "accept: application/json"