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

Postman获取token的POST请求转curl后报Bad Request问题求助

问题原因及修复方案
  • 核心错误为请求头与请求体格式不匹配:你设置了Content-Type: x-www-form-urlencoded请求头,但--data参数传入的是JSON格式字符串,两种格式完全不兼容,接口无法解析请求内容自然返回Bad Request。

方案1:接口要求x-www-form-urlencoded格式(与你当前设置的请求头匹配)

将JSON格式的请求体改为key=value用&拼接的表单格式即可,示例命令如下:

curl --request POST \
--header "Content-Type: x-www-form-urlencoded" \
--data "resource=https://xxxxx.com/resources&scope=openid&client_id=xxx-xxx-x-xxx&client_secret=xxxx-xxxxxx-xxxx" \
https://xxxxx-xxxxx.com/api/token

方案2:接口要求JSON格式

将请求头修改为JSON对应类型即可,示例命令如下:

curl --request POST \
--header "Content-Type: application/json" \
--data '{"resource":"https://xxxxx.com/resources","scope": "openid","client_id":"xxx-xxx-x-xxx","client_secret":"xxxx-xxxxxx-xxxx"}' \
https://xxxxx-xxxxx.com/api/token

额外操作提示:你可以直接从Postman导出可用的curl命令,无需手动编写:打开对应请求页面,点击右侧</>代码图标,在下拉菜单选择cURL选项即可直接复制可用命令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.23 20:54:01