【问题标题】:Neo4j PHP Graphaware '415 Unsupported Media Type 'Neo4j PHP Graphaware '415 不支持的媒体类型'
【发布时间】:2020-06-20 18:04:11
【问题描述】:

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


    <?php
    require 'vendor/autoload.php';
    
    use GraphAware\Neo4j\Client\ClientBuilder;
    
        $client = ClientBuilder::create()
        ->addConnection('default','http://neo4j:neo4j@localhost:7474')
        ->build();
    
        $result = $client->run('match (n:person) return n');

给我以下错误:


Fatal error: Uncaught Http\Client\Common\Exception\ClientErrorException: Unsupported Media Type in C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\client-common\src\Plugin\ErrorPlugin.php:72 Stack trace: #0 C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\client-common\src\Plugin\ErrorPlugin.php(54):HttpClientCommonPluginErrorPlugin->transformResponseToException(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\httplug\src\Promise\HttpFulfilledPromise.php(34): Http\Client\Common\Plugin\ErrorPlugin->Http\Client\Common\Plugin\{closure}(Object(GuzzleHttp\Psr7\Response)) #2 C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\client-common\src\Plugin\ErrorPlugin.php(55): Http\Client\Promise\HttpFulfilledPromise->then(Object(Closure)) #3 C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\client-common\src\PluginClient.php(161): Http\Client\Common\Plugin\ErrorPlugin->handleRequest(Object(GuzzleHttp\Psr7\Request), Object(Closure), in C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\client-common\src\Plugin\ErrorPlugin.php on line 72

这是我 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 浏览器客户端 然后它按预期工作。

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

【问题讨论】:

    标签: php neo4j cypher


    【解决方案1】:

    我看到了同样的问题:(

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

    public function flush(Pipeline $pipeline)
        {
            $request = $this->prepareRequest($pipeline);
            try {
                $response = $this->httpClient->sendRequest($request);
    
    value of request
    [headers:GuzzleHttp\Psr7\Request: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'
    ];
    

    【讨论】:

      猜你喜欢
      • 2014-05-10
      • 2019-05-01
      • 2017-06-30
      • 2017-07-05
      • 2016-11-26
      • 2015-08-21
      • 2015-08-29
      相关资源
      最近更新 更多