Newtonsoft JSON Schema - $ ref未解析,获取url的身份验证错误

时间:2016-01-18 10:37:41

标签: json json.net jsonschema

我正在尝试使用来自网址&的$ 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"
                            }
                        ]
                    }
                ]
            }
        }
    }
    
  3. 我创建了一个示例web api应用程序,用于将子模式下载为json。 在主模式http://localhost:49735/api/Schema/Sample中引用了URL api是使用无身份验证模式开发的。 我正在使用NewtonSoft JSON Schema来验证json数据。但是在解析json架构时,它会抛出异常。

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

1 个答案:

答案 0 :(得分:0)

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