以下测试用例(假设密码正确)
<?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浏览器客户端中 然后它会按预期工作。
知道为什么我会收到此错误吗?
答案 0 :(得分:3)
根据GraphAware PHP Client,您似乎未使用最新版本,因此您需要更新,请 OR ,您点击了the empty array bug(例如,您的问题是您没有不会发送 Content-Type:application / json ,似乎只使用 GraphAware \ Neo4j \ Client \ HttpDriver \ Session 中的函数 prepareRequest 进行设置>)。另外,请查看您的查询语法,因为对于Neo4j,Install instructions和the developer documentation中似乎已弃用了该语法。
答案 1 :(得分:0)
我面临着同样的问题,就我而言,解决方案是将PHP从7.1降级到7.0。这应该可以帮助您。
答案 2 :(得分:0)
请安装php-curl模块并尝试,它应该可以工作。
在这里讨论:https://github.com/graphaware/neo4j-php-client/issues/142#issuecomment-558857861