为什么curl json身份验证不起作用?

时间:2018-11-04 13:17:44

标签: json curl

当我使用此代码进行身份验证时:

curl -d -H "Accept: application/json" \
{"id":"1","method":"authenticate","params":{"user":"USER","password":"PASSWORD","client":"CLIENT", "?school":"htl-donaustadt"},"jsonrpc":"2.0"} \
https://melete.webuntis.com/WebUntis/jsonrpc.do?school=htl-donaustadt \
--insecure

我收到此错误消息:

  

卷曲:(3)第27列中的[匹配]不匹配的大括号/括号

     

{“ jsonrpc”:“ 2.0”,“ id”:null,“错误”:{“代码”:-32700,“消息”:“解析错误:由于输入结束,没有内容要映射\ n在[来源:org.apache.catalina.connector.CoyoteInputStream@102d63fc;行:1,列:0]“}}

2 个答案:

答案 0 :(得分:0)

要以JSON格式发布数据,请添加-H "Content-Type: application/json"。没有这个,curl将使用application/x-www-form-urlencoded

JSON帖子数据也需要加引号,并在-d标志后立即设置。

根据您的原始命令,尝试:

curl -H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"id":"1","method":"authenticate","params":{"user":"USER","password":"PASSWORD","client":"CLIENT", "?school":"htl-donaustadt"},"jsonrpc":"2.0"}' \
'https://melete.webuntis.com/WebUntis/jsonrpc.do?school=htl-donaustadt' \
--insecure

答案 1 :(得分:0)

根据一些非公开文档,您需要执行的请求是使用https://server.webuntis.com/WebUntis/jsonrpc.do?school=School+name网址,该网址为正文。很抱歉,我无法与您共享文档。我想您可以在Untis帮助台提出要求。

{
    "params": {
        "user": "xxx_user",
        "password": "xxx_password",
        "client": "Roostersync proxy"
    },
    "id": "random_id_here",
    "method": "authenticate",
    "jsonrpc": "2.0"
}

或curl命令

curl -X POST \
  'https://melete.webuntis.com/WebUntis/jsonrpc.do?school=htl-donaustadt' \
  -H 'Content-Type: application/json' \
  -d '{
    "params": {
        "user": "user",
        "password": "password",
        "client": "Your client name"
    },
    "id": "7e6431bc-36c2-4118-991d-6459ab5b01e2",
    "method": "authenticate",
    "jsonrpc": "2.0"
}'
相关问题