【问题标题】:Cisco ACI Authentication with cURL doesn't work使用 cURL 的 Cisco ACI 身份验证不起作用
【发布时间】:2020-06-07 22:08:38
【问题描述】:

我一直在阅读有关 Cisco ACI Automation with cURL here 并尝试遵循相同的步骤。

很遗憾,该代码不适用于 cURL。我收到以下错误。

C:\>curl -X POST -k https://x.x.x.x/api/aaaLogin.json -d '{"aaaUser":{"attributes":{"name":"user007","pwd":"password007"}}}'
{"totalCount":"1","imdata":[{"error":{"attributes":{"code":"400","text":"JSON parsing failed - incomplete attribute value at line: 1"}}}]}
C:\>

但是,当我使用 Postman 测试相同的代码时,它的工作就像一个魅力。 curl 命令出了什么问题?

注意:我没有在此示例中输入 -c cookie.txt,因为即使它存在,我也会遇到相同的错误。

期望的输出

获得正确的 HTTP 200 响应,而不是 400 Bad Request ..

【问题讨论】:

  • 你没有错过-c cookie.txt 部分吗?
  • 即使使用-c cookie.txt 仍然出现同样的错误

标签: curl postman cisco


【解决方案1】:

您需要先登录:

curl -X POST -k https://APIC_IP_ADDRESS/api/aaaLogin.xml -d '<aaaUser name="USERNAME" pwd="PASSWORD"/>' -c cookie.txt

APIC 控制器返回存储在 cookie 中的令牌。它将持续 5 分钟。您必须使用此 cookie 来运行任何以下 REST API

例如,创建新 Tenat、新应用程序配置文件和新 EPG 的 REST API 将如下所示:

curl -b cookie.txt -X POST -k https://APIC_IP_ADDRESS/api/node/mo/uni.xml -d '<polUni> <fvTenant name="TENANT-NAME" descr="TENANT-NAME-DESC" status=""> <fvAp name="APP-PROF-NAME">   <fvAEPg name="NEW-EPG-NAME" > </fvAEPg> </fvAp> </fvTenant> </polUni>' -c cookie.txt

【讨论】:

    【解决方案2】:

    你需要对双引号(")进行转义

    C:\>curl -X POST -k https://x.x.x.x/api/aaaLogin.json -d '{\"aaaUser\":{\"attributes\":{\"name\":\"user007\",\"pwd\":\"password007\"}}}'
    

    事实上,你甚至可以只对用户名和密码使用双引号:

    C:\>curl -X POST -k https://x.x.x.x/api/aaaLogin.json -d '{aaaUser:{attributes:{name:\"user007\",pwd:\"password007\"}}}'
    

    您需要转义 \" 的原因是因为 curl 在构造和发送 POST 消息时会删除它们。这是来自 whireshark 的捕获:whireshark capture

    参考:https://stackoverflow.com/a/15828662/147637

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-08
      • 1970-01-01
      • 2012-10-04
      • 1970-01-01
      • 2012-08-04
      • 1970-01-01
      相关资源
      最近更新 更多