Azure ADF中使用REST API Basic Authentication时遇输入格式错误
问题排查:REST API POST + Basic Auth 报错“输入格式不正确/无法获取实体详情”
错误信息
错误:输入格式不正确。原因:无法获取DandB Test的实体详情。如果此实体是链接服务,请确保在调试运行前已发布。
原始配置
{ "name": "DandB Test", "properties": { "activities": [ { "name": "Web1", "type": "WebActivity", "dependsOn": [], "policy": { "timeout": "0.12:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "method": "POST", "headers": { "Content-Type": "application/x-www-form-urlencoded", "Cache-Control": "no-cache" }, "url": "https://plus.dnb.com/v3/token", "body": { "value": "@concat('grant_type=client_credentials&client_id=',pipeline().parameters.ClientID,'&client_secret=',pipeline().parameters.ClientSecret)", "type": "Expression" }, "authentication": { "type": "Basic", "username": { "value": "{pipeline.parameters.client_id}", "type": "Expression" }, "password": { "type": "SecureString", "value": "**********" } } } ] }
问题分析与解决方案
1. 表达式语法错误
Basic Auth的username表达式格式错误:
- Data Factory中表达式必须以
@开头,而非{} - 参数名大小写不一致:body中用的是
ClientID,这里写的是client_id,参数名大小写敏感,会导致无法读取参数值
2. 认证方式冲突
D&B的token接口使用client_credentials模式时,只需在请求体中传递grant_type、client_id、client_secret即可,同时启用Basic Auth会导致接口接收到重复的认证信息,触发“输入格式不正确”错误。
3. 实体发布问题
如果"DandB Test"是链接服务,必须先发布该链接服务再调试;如果是管道名称,需确保管道已发布后再执行运行操作。
修正后的配置示例
选择client_credentials模式(移除Basic Auth):
{ "name": "DandB Test", "properties": { "activities": [ { "name": "Web1", "type": "WebActivity", "dependsOn": [], "policy": { "timeout": "0.12:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "method": "POST", "headers": { "Content-Type": "application/x-www-form-urlencoded", "Cache-Control": "no-cache" }, "url": "https://plus.dnb.com/v3/token", "body": { "value": "@concat('grant_type=client_credentials&client_id=', pipeline().parameters.ClientID, '&client_secret=', pipeline().parameters.ClientSecret)", "type": "Expression" } } } ] } }
额外注意事项
- 确认管道参数
ClientID和ClientSecret已正确定义,参数值需匹配D&B平台提供的凭证 - 若必须使用Basic Auth,需确认D&B接口支持该认证方式,同时移除body中的
client_id和client_secret,并将username修正为@pipeline().parameters.ClientID - 调试前确保相关实体(链接服务/管道)已完成发布
内容的提问来源于stack exchange,提问作者Priyanka
相关产品推荐
相关产品推荐

