【问题标题】:JSON format Not supported exception from Azure storage REST APIJSON 格式 Azure 存储 REST API 中不支持的异常
【发布时间】:2018-12-11 09:52:27
【问题描述】:

我正在处理 Azure 存储表上的 REST API 调用,我成功地查询表并获得了 xml 格式的响应,但是当我尝试将 Accept 标头更改为 JSON 时,我遇到了异常。

注意:我将 x-ms-version 的值设置为 2018-03-28

    headers.put("Authorization", "SharedKey " + store + ":" + hash);
    headers.put("x-ms-date", date);
//        headers.put("x-ms-version","2009-09-19");
    headers.put("x-ms-version","2018-03-28");
    headers.put("Accept-Charset","UTF-8");
//        headers.put("Accept","application/atom+xml,application/xml");
    headers.put("Accept","application/json;odata=nometadata");
    headers.put("DataServiceVersion","1.0;NetFx");
    headers.put("MaxDataServiceVersion","1.0;NetFx");

我收到响应状态代码 415,消息为“JsonFormatNotSupportedJSON 格式不受支持。”

【问题讨论】:

    标签: rest azure azure-storage


    【解决方案1】:

    DataServiceVersionMaxDataServiceVersion不是必须的,但是如果你想使用,把它们改成3.0;NetFx

    只有 3.0 与 x-ms-version 2013-08-15 or later 兼容。请参阅document

    【讨论】:

    • 非常感谢@Jerry,我们都同时得到了解决方案 :)
    【解决方案2】:

    我已删除以下 2 个标头,现在我收到 JSON 格式的响应。

        headers.put("DataServiceVersion","1.0;NetFx");
        headers.put("MaxDataServiceVersion","1.0;NetFx");
    

    【讨论】:

    • 请删除此答案并接受 Jerry Liu 的回答。
    • @ZhaoxingLu-Microsoft Sai 仅间隔 10 秒发布了他们的答案,因此它不是重复的。我不同意它应该被删除。 - From review
    • 我没有删除我的解决方案(我在发帖后看到了回复),但我接受了@Jerry 的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-13
    • 2017-11-15
    • 2016-06-17
    • 2012-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多