【问题标题】:Drupal-8 restful webservices only delivering HTMLDrupal-8 restful webservices 只提供 HTML
【发布时间】:2015-07-05 12:30:00
【问题描述】:

我有一个全新配置的 Drupal 8.0 beta 12,启用了 HAL、HTTP 基本身份验证、RESTful Web 服务和序列化模块。安装位于子文件夹 (D8_beta12) 中。当我访问创建的第一页 (id=1) 的 Web 服务时,例如

curl -H "Accept: application/json" --request GET http://localhost/d8_beta12/node/1

DRUPAL 只提供节点的 HTML 格式。我曾尝试通过 REST UI 仅配置为 JSON,但这并没有帮助。即使 Web 服务被禁用,DRUPAL 也会响应请求。

可能是坐在 DRUPAL 前面的用户(我)是问题 - 但我不明白。感谢任何帮助 - 我一直在为此工作,查看所有 DRUPAL 论坛和这里。

谢谢, 安迪

【问题讨论】:

  • 顺便说一句:我也尝试过 DRUPAL 8.0 开发版本 - 结果相同。

标签: web-services rest drupal-8


【解决方案1】:

我得到了同样的结果,并发现了一个关于它的注释https://drupal.stackexchange.com/questions/161421/d8-services-errors-no-route-found-for-the-specified-formats

所以我将请求更新为:

node/1?_format=json

更新:在 webchick 幻灯片中找到了关于它的注释: http://www.slideshare.net/webchickenator/plain-english-guide-to-drupal-8-criticals/51

【讨论】:

  • 谢谢!给其他人的注意事项:cookie auth 需要在 admin/config/services/rest 中选择
【解决方案2】:

请尝试将aaplication/json 替换为application/hal+json

curl -H "Accept: application/hal+json" --request GET http://localhost/d8_beta12/node/1

您可能还想通过this precise tutorial

【讨论】:

    【解决方案3】:

    如果您正在尝试来自邮递员,或者来自您正在尝试的其他 api,请确保您遵循以下格式

        http://localhost/da/drupal819/node/253?_format=json
    
    output
    
    {
      "nid": [
        {
          "value": "253"
        }
      ],
      "uuid": [
        {
          "value": "6f255c93-6886-4c38-b4cb-c40469073d1c"
        }
      ],
      "vid": [
        {
          "value": "253"
        }
      ],
      "langcode": [
        {
          "value": "en"
        }
      ],
      "type": [
        {
          "target_id": "article",
          "target_type": "node_type",
          "target_uuid": "ee2c7b5e-d57e-4714-9193-daff153c63ff"
        }
      ],
      "title": [
        {
          "value": "Commodo Pagus Quia"
        }
      ],
      "uid": [
        {
          "target_id": "14",
          "target_type": "user",
          "target_uuid": "0b8602ec-8003-4e3d-8406-5bd53e47df71",
          "url": "/da/drupal819/user/14"
        }
      ],
      "status": [
        {
          "value": "1"
        }
      ],
      "created": [
        {
          "value": "1474126412"
        }
      ],
      "changed": [
        {
          "value": "1474175616"
        }
      ],
      "promote": [
        {
          "value": "1"
        }
      ],
      "sticky": [
        {
          "value": "0"
        }
      ],
      "revision_timestamp": [
        {
          "value": "1474175616"
        }
      ],
      "revision_uid": [
        {
          "target_id": "14",
          "target_type": "user",
          "target_uuid": "0b8602ec-8003-4e3d-8406-5bd53e47df71",
          "url": "/da/drupal819/user/14"
        }
      ],
      "revision_log": [],
      "revision_translation_affected": [
        {
          "value": "1"
        }
      ],
      "default_langcode": [
        {
          "value": "1"
        }
      ],
      "path": [],
      "body": [
        {
          "value": "Duis revitas melior paulatim quibus quidne rusticus velit vereor.\n\n",
          "format": "plain_text",
          "summary": "Duis vitas melior paulatim quibus quidne rusticus velit vereor.\n\n"
        }
      ],
      "comment": [
        {
          "status": "2",
          "cid": "165",
          "last_comment_timestamp": "1474175616",
          "last_comment_name": "",
          "last_comment_uid": "13",
          "comment_count": "1"
        }
      ],
      "field_image": [
        {
          "target_id": "248",
          "alt": "Diam iriure neo quadrum refero valetudo verto ymo.",
          "title": "Os patria refoveo si valetudo.",
          "width": "225",
          "height": "526",
          "target_type": "file",
          "target_uuid": "02050136-7a51-4183-9c28-7d7cc793183a",
          "url": "http://localhost/da/drupal819/sites/default/files/2016-09/gen8C.tmp.jpeg"
        }
      ],
      "field_tags": []
    }
    

    你也可以试试其他格式

    1) http://localhost/da/drupal819/node/253?_format=hal_json

    2)http://localhost/da/drupal819/node/253?_format=xml

    要支持上述所有格式,您需要从管理面板的其余配置中支持该格式 甚至您需要从匿名用户的权限页面提供获取休息呼叫的权限。

    【讨论】:

      猜你喜欢
      • 2014-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-31
      • 2011-11-21
      • 1970-01-01
      相关资源
      最近更新 更多