从 Postman 到 Jdoodle API 的 POST 请求失败

问题描述 投票:0回答:1

我在 jdoodle 上创建了一个帐户并购买了一个免费计划,我们每天可以发出 200 个请求,从那里我获得了向他们的 api 发出请求的凭据(clientId 和 clientSecret)。

我正在从邮递员向 Jdoodle api 发出发布请求。尽管凭据有效,但它还是以未经授权的请求的形式向我提供状态代码 401 的响应。 当我请求检查使用的积分或(我对他们的 api 进行了多少次调用)时,也会给我未经授权的请求错误。

POST- https://api.jdoodle.com/v1/execute/

{
    "clientID" : "83xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
    "clientSecret" : "30xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
    "script" : "console.log('hello')", 
    "language" : "nodejs", 
    "versionIndex" : "0"
}

我得到的回应是 -

{
    "error": "Unauthorized Request",
    "statusCode": 401
}

POST-https://api.jdoodle.com/v1/credit-spent

{
    "clientID" : "83xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
    "clientSecret" : "30xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}

我得到的回应是 -

{
    "error": "Unauthorized Request",
    "statusCode": 401
}

我不知道为什么尽管所有有效的凭据和参数我都会得到这样的响应。

post postman jdoodle
1个回答
0
投票

使用这个邮递员集合。大多数情况下,您的问题似乎与身份验证有关。确保 client_id 和 Secret 是否被安全替换。

{
    "auth": null,
    "event": null,
    "info": {
        "_postman_id": null,
        "description": null,
        "name": "JDoodle Compiler API.http",
        "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
        "version": null
    },
    "item": [
        {
            "description": null,
            "event": null,
            "id": null,
            "name": "Execute Program",
            "protocolProfileBehavior": null,
            "request": {
                "auth": null,
                "body": {
                    "disabled": null,
                    "file": null,
                    "formdata": null,
                    "graphql": null,
                    "mode": "raw",
                    "options": {
                        "language": "json"
                    },
                    "raw": "{\"clientId\": \"{{clientId}}\", \"clientSecret\": \"{{clientSecret}}\", \"script\": \"print 'hello'\", \"language\": \"python2\", \"versionIndex\": \"0\"}",
                    "urlencoded": null
                },
                "certificate": null,
                "description": "Execute Program",
                "header": [
                    {
                        "description": null,
                        "disabled": false,
                        "key": "content-type",
                        "value": "application/json"
                    }
                ],
                "method": "POST",
                "proxy": null,
                "url": "https://api.jdoodle.com/v1/execute/"
            },
            "response": null,
            "variable": null,
            "auth": null,
            "item": null
        }
    ],
    "protocolProfileBehavior": null,
    "variable": [
        {
            "description": null,
            "disabled": false,
            "id": null,
            "key": "baseUrl",
            "name": null,
            "system": null,
            "type": null,
            "value": "httpsDefaultParameterValue:[email protected]/"
        },
        {
            "description": null,
            "disabled": false,
            "id": null,
            "key": "id",
            "name": null,
            "system": null,
            "type": null,
            "value": "<post>"
        },
        {
            "description": null,
            "disabled": false,
            "id": null,
            "key": "event_id",
            "name": null,
            "system": null,
            "type": null,
            "value": "<>"
        }
    ]
}

使用 dothttp 请求非常简单且易于共享

@name("Execute Program")
POST "https://api.jdoodle.com/v1/execute/"
json({
    "clientId": "{{clientId}}",
    "clientSecret": "{{clientSecret}}",
    // "script": '<?php echo "hello"; ?>',
    // "language": "php",
    "script" :"print 'hello'",
    "language": "python2",
    // "stdin": "",
    "versionIndex": "0"
})
© www.soinside.com 2019 - 2024. All rights reserved.