【问题标题】:eBay API returns JSON when text/plain is specified in header当标头中指定 text/plain 时,eBay API 返回 JSON
【发布时间】:2013-11-20 21:09:15
【问题描述】:

我正在寻找一些观点。我对 API 编程完全陌生。我发现调用 eBay 的 GeteBayTime 方法正确返回 JSON,但标题为 text/plain;charset=utf-8,而不是 application/json。这是一个 eBay 的错误,只是平均的 API 怪异,在某种程度上可以接受还是什么?这可能是我的错误吗?我正在使用 C++ Rest SDK 进行客户端 API 访问。

对于那些面临同样问题的人,解决方案是使用 set_content_type() 更改响应标头:

    if (response.status_code() == status_codes::OK)
    {
        response.headers().set_content_type(L"application/json");
        return response.extract_json();
    }

实际请求使用:

http://open.api.sandbox.ebay.com/shopping?callname=GeteBayTime&responseencoding=JSON&appid=<my appid>&siteid=0&version=713

【问题讨论】:

    标签: c++ json rest sdk ebay-api


    【解决方案1】:

    我在https://casablanca.codeplex.com/discussions/470633 收到了很好的回复。我相信还有更多的讨论空间。在那之前,这将是固定答案。

    【讨论】:

    • 如何发送 GET 请求并接收 JSON 作为结果而不是文本?根据您的链接,我没有看到任何解决方案。我遇到了同样的问题,即使我将 Accept 和 Content-type 标头设置为 application/json,我总是得到 text/plain
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 2012-05-19
    相关资源
    最近更新 更多