简体   繁体   English

使用 cURL 的 Cisco ACI 身份验证不起作用

[英]Cisco ACI Authentication with cURL doesn't work

I've been reading about Cisco ACI Automation with cURL here and trying to follow the same steps.我一直在阅读有关思科ACI自动化与卷曲这里,并试图按照同样的步骤。

Unfortunately, the code doesn't work on cURL.不幸的是,该代码不适用于 cURL。 I'm getting the following error.我收到以下错误。

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:\>

However, when I test the same code using Postman, it's working like a charm.然而,当我使用 Postman 测试相同的代码时,它就像一个魅力。 What was wrong with the curl command? curl 命令有什么问题?

Note: I did not put -c cookie.txt in this example as I'm getting the same error even if it's there.注意:我没有将-c cookie.txt放在这个例子中,因为即使它在那里我也会得到同样的错误。

Desired Output期望输出

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

You need first to login:您需要先登录:

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

The APIC controller returns a token stored in a cookie. APIC 控制器返回存储在 cookie 中的令牌。 It will last for 5 minutes.它将持续 5 分钟。 You must use this cookie to run any following REST API .您必须使用此 cookie 来运行任何以下REST API

For example the REST API that creates a new Tenat, a new Application Profile and a new EPG will look like this:例如,创建新 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

You need to escape the double quotes (")您需要转义双引号 (")

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

In fact, you can even use the double quotes for user and password only:事实上,你甚至可以只对用户和密码使用双引号:

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

The reason you need to escape the \\" is because curl will remove them when constructing and sending the POST message. This is a capture from whireshark: whireshark capture你需要转义 \\" 的原因是因为 curl 在构造和发送 POST 消息时会删除它们。这是来自 whireshark 的捕获: whireshark capture

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM