4

我有一个新配置的 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 论坛和此处。

谢谢,安迪

4

3 回答 3

2

我得到了同样的结果并找到了关于它的注释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

于 2015-07-05T18:16:30.127 回答
1

请尝试替换aaplication/jsonapplication/hal+json.

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

您可能还想通过这个精确的教程

于 2015-07-05T14:33:17.703 回答
1

来自邮递员(如果您正在尝试)或来自其他您正在尝试的其他 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

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

于 2016-09-18T23:12:05.997 回答