You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Curl请求Spotify访问令牌遇URL拒绝及411错误的解决咨询

错误原因拆解
  • "URL rejected: Bad hostname":要么是Spotify API URL拼写错误(比如把https://accounts.spotify.com/api/token写成了错误地址),要么是命令里的引号、空格格式混乱,导致curl把部分请求头/参数内容当成主机名解析。
  • 411 Length Required:Spotify的token接口要求POST请求必须携带请求体(需传递grant_type、client_id、client_secret这些参数),如果没传请求体,或者curl未正确识别请求体,服务器就会返回该错误,提示需要Content-Length头(curl通常会自动添加,但无请求体时无法生成)。
  • '-H'未被系统识别:属于命令格式问题,比如在Windows CMD里引号规则和Linux/macOS的bash不同,或者-H前有多余空格、引号配对错误,导致系统把-H当成独立命令而非curl的参数。
正确的Curl命令示例

Linux/macOS(Bash/Zsh)

curl -X POST "https://accounts.spotify.com/api/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials&client_id=你的客户端ID&client_secret=你的客户端密钥"

Windows CMD

curl -X POST "https://accounts.spotify.com/api/token" ^
  -H "Content-Type: application/x-www-form-urlencoded" ^
  -d "grant_type=client_credentials&client_id=你的客户端ID&client_secret=你的客户端密钥"

Windows PowerShell

Invoke-RestMethod -Uri "https://accounts.spotify.com/api/token" -Method Post -ContentType "application/x-www-form-urlencoded" -Body @{
    grant_type = "client_credentials"
    client_id = "你的客户端ID"
    client_secret = "你的客户端密钥"
}

注意:将命令里的你的客户端ID和你的客户端密钥替换为Spotify开发者后台获取的真实信息。

内容的提问来源于stack exchange,提问作者TheOx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 19:02:33