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

Ste*_*nou 6 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];
?>
Run Code Online (Sandbox Code Playgroud)

给我以下错误:

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/
Run Code Online (Sandbox Code Playgroud)

当我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) {
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我不知道如何解释这个或什么是错的.

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

  • 据我所知,graphaware已按照网站上的说明正确安装.

  • 我已经测试过,错误发生在运行查询时,而不是在创建客户端时(即使错误没有明确指出).

  • 如果我将查询直接复制/粘贴到neo4j浏览器客户端,那么它会按预期工作.

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

Gil*_* AB 3

根据GraphAware PHP 客户端,您似乎没有使用最新版本,因此您需要更新,或者您遇到了空数组错误(例如,您的问题是您没有发送Content-Type:application/json,这似乎只能使用GraphAware\Neo4j\Client\HttpDriver\Session中的函数prepareRequest进行设置)。另请查看您的查询语法,因为它似乎在安装说明和Neo4j开发人员文档中已被弃用。