【问题标题】:Newtonsoft JSON Schema - $ref is not resolved, getting authentication error for urlNewtonsoft JSON Schema - $ref 未解析,获取 url 的身份验证错误
【发布时间】:2016-01-18 10:37:40
【问题描述】:

我正在尝试使用来自 URL 的 $ref 并使用 NewtonSoft.Json.Schema 验证 json 数据。

  1. MainSchema.json

    {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
            "Data": { "$ref": "http://localhost:49735/api/schema/sample" },
        },
        "required": [ "Data" ]
    }
    
  2. SubSchema.json

    {
       "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": 
        {
            "Data": 
            {
                "type": "array",
                "items": 
                [
                    {
                        "type": "array",
                        "items": 
                        [
                            {
                                "id": "id1",
                                "type": "string",
                            },
                            {
                                "id": "id2",
                                "type": "number"
                            }
                        ]
                    }
                ]
            }
        }
    }
    

我创建了一个示例 Web api 应用程序,用于将子模式下载为 json。 URL 在主模式 http://localhost:49735/api/Schema/Sample 中被引用 该 api 是使用无身份验证模式开发的。 我正在使用 NewtonSoft JSON Schema 来验证 json 数据。但是在解析 json 架构时它会抛出异常。

"The remote server returned an error: (401) Unauthorized."

【问题讨论】:

  • 尝试将 $ref uri 复制到浏览器中,并使用 Web 开发人员工具中的网络工具测试响应。或使用curl。如果有 401 响应,则错误在您的服务器配置中。
  • 从浏览器可以正常工作。似乎只是因为无法使用 n/w 代理

标签: json json.net jsonschema


【解决方案1】:

这可能是您本地网络上的代理问题。您可以尝试配置 .NET 以使用您计算机配置的代理 - How to authenticate against a proxy when using the HttpClient class?

【讨论】:

  • 这只是问题所在。我使用了代理,它解决了我的问题。谢谢詹姆斯。
猜你喜欢
  • 2018-05-09
  • 1970-01-01
  • 1970-01-01
  • 2019-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-11
相关资源
最近更新 更多