php - Neo4j PHP Graphaware '400 Bad Content-Type header' 错误

标签 php neo4j graphaware

下面的测试用例(假设密码正确)

<?php
    require_once "vendor/autoload.php";
    use GraphAware\Neo4j\Client\ClientBuilder;
    $client = ClientBuilder :: create() -> addConnection("default", "http://neo4j:Password@localhost:7474") -> build();
    $query  = "MATCH (u:User)
               RETURN u";
    $result = $client -> run($query);
    $user = $result -> firstRecord() -> values()[0];
?>

给我以下错误:

PHP Fatal error:  Uncaught GuzzleHttp\\Exception\\ClientException: Client error: `POST http://neo4j:***@localhost:7474/db/data/transaction/commit` resulted in a `400 Bad Content-Type header value: ''` response in /var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\\Exception\\RequestException::create(Object(GuzzleHttp\\Psr7\\Request), Object(GuzzleHttp\\Psr7\\Response))
#1 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\\Middleware::GuzzleHttp\\{closure}(Object(GuzzleHttp\\Psr7\\Response))
#2 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\\Promise\\Promise::callHandler(1, Object(GuzzleHttp\\Psr7\\Response), Array)
#3 /var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\\Promise\\Promise::GuzzleHttp\\Promise\\{closure}()
#4 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(246): GuzzleHttp\\Promise\\TaskQueue->run(true)
#5 /var/www/html/vendor/guzzlehttp/ in /var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113, referer: http://localhost/

这是我 var_dump 时的 $client:

object(GraphAware\Neo4j\Client\Client)#7 (2) {
  ["connectionManager":protected]=>
  object(GraphAware\Neo4j\Client\Connection\ConnectionManager)#2 (2) {
    ["connections":"GraphAware\Neo4j\Client\Connection\ConnectionManager":private]=>
    array(1) {
      ["default"]=>
      object(GraphAware\Neo4j\Client\Connection\Connection)#4 (5) {
        ["alias":"GraphAware\Neo4j\Client\Connection\Connection":private]=>
        string(7) "default"
        ["uri":"GraphAware\Neo4j\Client\Connection\Connection":private]=>
        string(38) "http://neo4j:Password@localhost:7474"
        ["driver":"GraphAware\Neo4j\Client\Connection\Connection":private]=>
        object(GraphAware\Neo4j\Client\HttpDriver\Driver)#6 (2) {
          ["uri":protected]=>
          string(38) "http://neo4j:Password@localhost:7474"
          ["config":protected]=>
          object(GraphAware\Neo4j\Client\HttpDriver\Configuration)#5 (1) {
            ["timeout":protected]=>
            int(5)
          }
        }
        ["session":"GraphAware\Neo4j\Client\Connection\Connection":private]=>
        NULL
        ["timeout":"GraphAware\Neo4j\Client\Connection\Connection":private]=>
        int(5)
      }
    }
    ["master":"GraphAware\Neo4j\Client\Connection\ConnectionManager":private]=>
    NULL
  }
  ["eventDispatcher":protected]=>
  object(Symfony\Component\EventDispatcher\EventDispatcher)#8 (2) {
    ["listeners":"Symfony\Component\EventDispatcher\EventDispatcher":private]=>
    array(0) {
    }
    ["sorted":"Symfony\Component\EventDispatcher\EventDispatcher":private]=>
    array(0) {
    }
  }
}

我不知道如何解释这个或者哪里出了问题。

  • 我的数据库在 neo4j 浏览器客户端中正常运行。

  • 据我所知,graphaware 已按照 网站上的说明。

  • 我已经测试过,错误发生在运行查询时, 不是在创建客户端的时候(即使这不是 错误清楚地指出了)。

  • 如果我将查询直接复制/粘贴到 neo4j 浏览器客户端 然后它按预期工作。

知道我为什么会收到此错误吗?

最佳答案

根据 GraphAware PHP Client你似乎没有使用最新版本,所以你需要更新,或者你点击了the empty array bug (例如,您的问题是您没有发送 Content-Type:application/json,这似乎只能使用 GraphAware\Neo4j\中的函数 prepareRequest 进行设置客户端\HttpDriver\ session )。还要查看您的查询语法,因为它似乎已在 Install instructions 中弃用。在the developer documentation对于 Neo4j。

关于php - Neo4j PHP Graphaware '400 Bad Content-Type header' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52084565/

相关文章:

neo4j - 在 Neo4j 中将参数传递给 gds.create.graph

java - 将节点转换为对象

php - 打开 Id XRDS 发现

neo4j - neo4j 中的节点标识符

php - 如何在 codeigniter 的核心函数中加载 View 文件

elasticsearch - 通过代理安装插件

java - 将 graphaware neo4j-reco 连接到独立的 neo4j 服务器

docker - 无法在docker中连接neo4j和elasticsearch

php - Laravel 5.2 的软删除级联

php - MySQL 列值在 OnClick 中破坏 HTML 语法