Neo4j PHP Graphaware '415 Unsupported Media Type '



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


<?php
require 'vendor/autoload.php';

use GraphAwareNeo4jClientClientBuilder;

$client = ClientBuilder::create()
->addConnection('default','http://neo4j:neo4j@localhost:7474')
->build();

$result = $client->run('match (n:person) return n');

给我以下错误:


Fatal error: Uncaught HttpClientCommonExceptionClientErrorException: Unsupported Media Type in C:UsersAliDesktopXamphtdocsNeo4jvendorphp-httpclient-commonsrcPluginErrorPlugin.php:72 Stack trace: #0 C:UsersAliDesktopXamphtdocsNeo4jvendorphp-httpclient-commonsrcPluginErrorPlugin.php(54):HttpClientCommonPluginErrorPlugin->transformResponseToException(Object(GuzzleHttpPsr7Request), Object(GuzzleHttpPsr7Response)) #1 C:UsersAliDesktopXamphtdocsNeo4jvendorphp-httphttplugsrcPromiseHttpFulfilledPromise.php(34): HttpClientCommonPluginErrorPlugin->HttpClientCommonPlugin{closure}(Object(GuzzleHttpPsr7Response)) #2 C:UsersAliDesktopXamphtdocsNeo4jvendorphp-httpclient-commonsrcPluginErrorPlugin.php(55): HttpClientPromiseHttpFulfilledPromise->then(Object(Closure)) #3 C:UsersAliDesktopXamphtdocsNeo4jvendorphp-httpclient-commonsrcPluginClient.php(161): HttpClientCommonPluginErrorPlugin->handleRequest(Object(GuzzleHttpPsr7Request), Object(Closure), in C:UsersAliDesktopXamphtdocsNeo4jvendorphp-httpclient-commonsrcPluginErrorPlugin.php on line 72

这是我var_dump它时$client:

object(GraphAwareNeo4jClientClient)#7 (2) {
["connectionManager":protected]=>
object(GraphAwareNeo4jClientConnectionConnectionManager)#2 (2) {
["connections":"GraphAwareNeo4jClientConnectionConnectionManager":private]=>
array(1) {
["default"]=>
object(GraphAwareNeo4jClientConnectionConnection)#4 (5) {
["alias":"GraphAwareNeo4jClientConnectionConnection":private]=>
string(7) "default"
["uri":"GraphAwareNeo4jClientConnectionConnection":private]=>
string(38) "http://neo4j:Password@localhost:7474"
["driver":"GraphAwareNeo4jClientConnectionConnection":private]=>
object(GraphAwareNeo4jClientHttpDriverDriver)#6 (2) {
["uri":protected]=>
string(38) "http://neo4j:Password@localhost:7474"
["config":protected]=>
object(GraphAwareNeo4jClientHttpDriverConfiguration)#5 (1) {
["timeout":protected]=>
int(5)
}
}
["session":"GraphAwareNeo4jClientConnectionConnection":private]=>
NULL
["timeout":"GraphAwareNeo4jClientConnectionConnection":private]=>
int(5)
}
}
["master":"GraphAwareNeo4jClientConnectionConnectionManager":private]=>
NULL
}
["eventDispatcher":protected]=>
object(SymfonyComponentEventDispatcherEventDispatcher)#8 (2) {
["listeners":"SymfonyComponentEventDispatcherEventDispatcher":private]=>
array(0) {
}
["sorted":"SymfonyComponentEventDispatcherEventDispatcher":private]=>
array(0) {
}
}
}

我不知道如何解释这一点或有什么问题。

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

  • 据我所知,graphaware 已按照网站上的
    说明进行了适当的安装。

  • 我已经测试过,错误发生在运行查询时, 不是在创建客户端时(即使这不是 错误清楚地表明(

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

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

我看到了同样的问题:(

我将其调试为 HttpDriver/Session.php 刷新函数,我认为标头设置不正确:

public function flush(Pipeline $pipeline)
{
$request = $this->prepareRequest($pipeline);
try {
$response = $this->httpClient->sendRequest($request);
value of request
[headers:GuzzleHttpPsr7Request:private] => Array
(
[Host] => Array
(
[0] => localhost:7474
)
[0] => Array
(
[X-Stream] => 1
[Content-Type] => application/json
)
)

很确定请求应该是这样的:

Array
(
[Host] => Array
(
[0] => localhost:7474
)
[X-Stream] => 1
[Content-Type] => application/json
)

为了解决这个问题,我修改了 PrepareRequst 函数以生成正确的标头

// Line 197
$headers = [
'X-Stream' => true,
'Content-Type' => 'application/json'
];

最新更新