问题:

linux下使用curl命令成功,在window下使用却报错:

400 Bad Request: Failed to decode JSON object: Expecting value: line 1

解决方法:

由于单引号在Linux和Windows的含义不同,curl调用格式也略有差异。Windows下双引号內部使用双引号需要"\"转义。

Linux下curl格式:

curl -d '{"auth_url": "http://IP:5000/v2.0","user": "user_name","key": "password","tenant_name": "tenantname"}' -H "Content-Type: application/json" -X POST  http://IP:5000/swift/api/v1.0/token

Windows下curl格式:

curl -d "{\"auth_url\": \"http://IP:5000/v2.0\",\"user\": \"user_name\",\"key\": \"password\",\"tenant_name\": \"tenantname\"}" -H "Content-Type: application/json" -X POST  http://IP:5000/swift/api/v1.0/token

更多推荐

Linux和Windows下使用curl命令格式差异