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

Neo4j PHP Graphaware '400 Bad Content-Type header' error

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

<?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 PHP Client you don't seem to use the latest version, so you need to update, OR you hit the empty array bug (e.g. Your problem is that you don't send Content-Type:application/json, that seems to only be set using function prepareRequest in GraphAware\Neo4j\Client\HttpDriver\Session). Also look at your query syntax since it seems to be deprecated in Install instructions and in the developer documentation

我遇到了同样的问题,就我而言,解决方案是将 PHP 从 7.1 降级到 7.0。这应该对你有帮助。

安装 php-curl 模块并尝试,它应该可以工作。

此处讨论:https://github.com/graphaware/neo4j-php-client/issues/142#issuecomment-558857861