代码之家  ›  专栏  ›  技术社区  ›  Jason

如何调试Azure API管理调用中的500错误?

  •  16
  • Jason  · 技术社区  · 7 年前

    {
      "statusCode": 500,
      "message": "Internal server error",
      "activityId": "79c1bef9-a05d-4734-b729-0657c1749e40"
    }
    

    我启用了跟踪,这是跟踪json

    {
    "traceId": "79c1bef9a05d4734b7290657c1749e40",
    "traceEntries": {
        "inbound": [
        {
            "source": "api-inspector",
            "timestamp": "2017-10-24T21:50:09.6322945Z",
            "elapsed": "00:00:00.0002259",
            "data": {
            "request": {
                "method": "GET",
                "url": "https://mysite.azure-api.net/partner/api/partner/ClientsActions",
                "headers": [
                {
                    "name": "Ocp-Apim-Subscription-Key",
                    "value": "..."
                },
                {
                    "name": "Connection",
                    "value": "Keep-Alive"
                },
                {
                    "name": "Host",
                    "value": "mysite.azure-api.net"
                }
                ]
            }
            }
        },
        {
            "source": "api-inspector",
            "timestamp": "2017-10-24T21:50:09.6322945Z",
            "elapsed": "00:00:00.0002352",
            "data": {
            "configuration": {
                "api": {
                "from": "/partner",
                "to": null,
                "version": null,
                "revision": "1"
                },
                "operation": {
                "method": "GET",
                "uriTemplate": "/api/partner/ClientsActions"
                },
                "user": {
                "id": "1",
                "groups": [
                    "Administrators",
                    "Developers"
                ]
                },
                "product": {
                "id": "57c59e76ea12f3007f060002"
                }
            }
            }
        },
        {
            "source": "cors",
            "timestamp": "2017-10-24T21:50:09.6322945Z",
            "elapsed": "00:00:00.0002544",
            "data": "Origin header was missing or empty and the request was classified as not cross-domain. CORS policy was not applied."
        },
        {
            "source": "choose",
            "timestamp": "2017-10-24T21:50:09.6322945Z",
            "elapsed": "00:00:00.0002633",
            "data": {
            "message": "Expression was successfully evaluated.",
            "expression": "context.Request.Url.Query.ContainsKey(\"key\")",
            "value": false
            }
        },
        {
            "source": "set-header",
            "timestamp": "2017-10-24T21:50:09.6322945Z",
            "elapsed": "00:00:00.0002744",
            "data": {
            "message": "Expression was successfully evaluated.",
            "expression": "(string)context.User.Id",
            "value": "1"
            }
        },
        {
            "source": "set-header",
            "timestamp": "2017-10-24T21:50:09.6322945Z",
            "elapsed": "00:00:00.0002802",
            "data": {
            "message": "Specified value was assigned to the header (see below).",
            "header": {
                "name": "x-client-id",
                "value": "1"
            }
            }
        }
        ],
        "backend": [
        {
            "source": "forward-request",
            "timestamp": "2017-10-24T21:50:09.6322945Z",
            "elapsed": "00:00:00.0002909",
            "data": {
            "message": "Backend service URL is not defined."
            }
        },
        {
            "source": "forward-request",
            "timestamp": "2017-10-24T21:50:09.6322945Z",
            "elapsed": "00:00:00.0004824",
            "data": {
            "messages": [
                null,
                "Backend service URL is not defined."
            ]
            }
        }
        ],
        "outbound": [
        {
            "source": "transfer-response",
            "timestamp": "2017-10-24T21:50:09.6322945Z",
            "elapsed": "00:00:00.0007989",
            "data": {
            "message": "Response headers have been sent to the caller."
            }
        },
        {
            "source": "transfer-response",
            "timestamp": "2017-10-24T21:50:09.6322945Z",
            "elapsed": "00:00:00.0008730",
            "data": {
            "message": "Response body streaming to the caller is complete."
            }
        }
        ]
    }
    }
    

    有人知道可能发生了什么,或者我应该看看什么吗?我直接通过Azure提供的开发者门户运行测试。

    5 回复  |  直到 7 年前
        1
  •  43
  •   Midas    6 年前

    我也有同样的问题。我通过将后端API URL放在API管理中API的“Web服务URL”上解决了这个问题。因此,在撰写本文时,使用门户的步骤将是:

    1. 打开API管理实例
    2. 打开API刀片
    3. 在列表中选择您的API
    4. 设置选项卡(>);Web服务URL属性
        2
  •  10
  •   zurebe-pieter    7 年前

    在您的Swagger文件中,确保它提到了正确的host、basePath和schemes条目。

    下面是一个示例:

    {
    "swagger": "2.0",
    "info": {
        "title": "Your title",
        "version": "1.0",
        "description": "Your description"
    },
    "host": "server.host.com",
    "basePath": "/api",
    "schemes": [
        "https"
    ],
    "consumes": [
        "application/json"
    ],
    "produces": [
        "application/json"
    ],
    

    特别关注“主机”、“基本路径”和“方案”,并根据API进行更改。

        3
  •  0
  •   Sachin Hayatnagarkar    6 年前

    在API管理中配置端点时,我遇到了类似的错误。当API管理无法验证SSL证书根权限链时,就会发生这种情况。如果您使用的是自签名证书,请使用下面的powershell跳过端点的证书链验证。

    $subscriptionName = "MySubscription"
    Get-AzureRmSubscription -SubscriptionName $subscriptionName | Set-AzureRmContext 
    
    $context = New-AzureRmApiManagementContext -resourcegroup 'myResourceGroup' -servicename 'myApiManagementServiceName'
    New-AzureRmApiManagementBackend -Context  $context -Url 'https://myService.abc.com/' -Protocol http -SkipCertificateChainValidation $true
    

    如果需要检查已设置哪些URL以跳过证书链验证,请使用下面的powershell命令-

    Get-AzureRmApiManagementBackend -Context $context
    
        4
  •  0
  •   Devanathan.S    6 年前

    最近我遇到了这个问题。正在使用虚张声势的皮带扣。AspNetCore,用于从api创建json文件元数据。由于某种原因,诸如host、schemes、securityDefinitions和apiKeyQuery之类的字段丢失了,原因不明。但在明确添加这些之后,问题解决了。在缺失字段下方

    "host": "your api host .com",
    "schemes": ["http", "https"],
    "securityDefinitions": {
        "apiKeyHeader": {
            "type": "apiKey",
            "name": "Ocp-Apim-Subscription-Key",
            "in": "header"
        },
        "apiKeyQuery": {
            "type": "apiKey",
            "name": "subscription-key",
            "in": "query"
        }
    },
    "security": [{
        "apiKeyHeader": []
    }, {
        "apiKeyQuery": []
    }],
    
        5
  •  -1
  •   Tommi Grönlund    4 年前

    我也有同样的错误,但意识到我有订阅要求,尽管我没有提供任何安全的键值。