【问题标题】:Why does the curl json authentication not work?为什么 curl json 身份验证不起作用?
【发布时间】:2019-04-08 00:52:17
【问题描述】:

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

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

我收到此错误消息:

curl: (3) [globbing] 第 27 列中不匹配的右大括号/方括号

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

【问题讨论】:

    标签: json curl


    【解决方案1】:

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

    JSON post 数据也需要被引用,并在-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
    

    【讨论】:

    • 当我使用这个代码时: 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"}' 'melete.webuntis.com/WebUntis/jsonrpc.do?school=htl-donaustadt' --insecure 我收到一条新的错误消息: curl:未指定 URL! curl:尝试“curl --help”或“curl --manual”以获取更多信息
    【解决方案2】:

    根据一些非公开文档,您需要做的请求是到https://server.webuntis.com/WebUntis/jsonrpc.do?school=School+name url,并以此作为正文。很抱歉,我无法与您分享文档。我想你可以在 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"
    }'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-04
      • 2019-10-31
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      相关资源
      最近更新 更多