2018-04-11 05:04
采纳率: 100%
浏览 203

PHP cURL 400错误无法满足请求

I'm using the bandsintown API for a personal project and my php code results in an error:

400 ERROR The request could not be satisfied. Bad Request

for some queries. I'm not sure why, and would like some help in fixing it. Thanks!

This is my code right now:


curl_setopt($ch, CURLOPT_URL, "".$artist."/events?app_id=".$app_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

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

$result = curl_exec($ch);


This results in an error on a fair number of artists and I'm not sure why.

Examples of some of the artists where this results in an error are those like BØRNS, MØ (which have normal results through a regular cURL request)

curl -X GET "$app_id" -H  "accept: application/json"

which I initially thought might have something to do with the non-standard characters.

But what makes me think this is another issue is that Calvin Harris and other similar artists with standard lettering throw the same error (and they also work fine on a regular cURL request)

curl -X GET "$app_id" -H  "accept: application/json"

So, I think there might be something wrong with the way I made my php cURL.

Any help would be much appreciated. Thanks again!

图片转代码服务由CSDN问答提供 功能建议

我正在使用bandsintown API进行个人项目,我的php代码导致错误:</ p>

  400 ERROR无法满足请求。 某些查询的错误请求
 </ code> </ pre> 

。 我不确定为什么,并希望得到一些帮助来解决它。 谢谢!</ p>

这是我现在的代码:</ p>

  $ ch = curl_init(); 
 ncurl_setopt($ ch,CURLOPT_URL  ,“".$artist."/events?app_id=".$app_id);
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); 
 </ code> </ pre> 

这会导致相当数量的艺术家出错,我不知道为什么 。 </ p>

导致错误的一些艺术家的例子是BØRNS,MØ(通过常规cURL请求获得正常结果)</ p>

  curl -X GET“$app_id”-H“accept:application / json”
 </ code> <  / pre> 

我最初认为可能与非标准字符有关。 </ p>

但让我觉得这是另一个问题的原因是Calvin Harris和其他类似的艺术家使用标准字体会产生同样的错误(并且它们在常规cURL请求下也能正常工作)</ p >

  curl -X GET“$app_id”-H“accept:application / json”
  </ code> </ pre> 

所以,我认为我的php cURL的方式可能有问题。</ p>

任何帮助都将非常感谢 。 再次感谢!</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题