调用未定义的函数GuzzleHttp \ Psr7 \ get_message_body_summary() [英] Call to undefined function GuzzleHttp\Psr7\get_message_body_summary()

查看:649
本文介绍了调用未定义的函数GuzzleHttp \ Psr7 \ get_message_body_summary()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在guzzlehttp中执行CURL获取请求,以检查CRM中是否存在用户.每当我尝试执行请求时,标题中都会出现以下错误,但我无法在线找到针对此特定问题的任何资源.任何想法都将非常有帮助,如果您需要任何其他信息,请在评论中让我知道.

I am trying to perform CURL get request in guzzlehttp to check if a user exists in a CRM. Whenever I try to perform the request I get the following error in the title, I haven't been able to find any resources online for this specific problem. Any ideas would be super helpful, if you require any additional info please let me know in the comments.

包含的软件包:

require(__DIR__ . "/../../vendor/autoload.php");
require_once(__DIR__ . "/../../helpers/Validation.php");
use Symfony\Component\Dotenv\Dotenv;
use GuzzleHttp\Client;
use GuzzleHttp\Request;
use GuzzleHttp\RequestOptions;
use GuzzleHttp\Psr7;
use GuzzleHttp\Stream\Stream;
use Drupal\Core\Site\Settings;

// Load our environment variables
$dotenv = new Dotenv();
$dotenv->load(__DIR__ . "/../../.env");

private function checkDuplicate() {
  // If no errors we can submit the registrant
  // \Drupal::logger('signup')->notice("access token", print_r($this->_accessToken, TRUE));
  if(!$this->_errors) {
    $checkNewUser = new Client();
    try {
      $options = [
        'headers' => [
        'Content-Type' => 'application/x-www-form-urlencoded',
        'Authorization' => "Bearer " . $this->_accessToken
      ],
      "query" => '$filter=email%20eq%20"' .$this->_email . '"&$fields=Contact Key,First Name,Last Name'
    ];
    $result = $checkNewUser->get($_ENV['REST_API_URL'], $options);
  } catch (RequestException $e) {
    \Drupal::logger('signup')->error("error " . print_r($e->getRequest(), TRUE));
    if ($e->hasResponse()) {
      \Drupal::logger('signup')->error("error " . print_r($e->getRequest(), TRUE));
      echo $e->getRequest() . "\n";
      \Drupal::logger('signup')->error("error " . print_r($e->getResponse(), TRUE));
    }
  }
}

我具有发布请求功能,以获取可以正常工作的访问令牌.

I have a post request function to gain an access token that works correctly.

private function getAccessToken() {
  try {
    $requestAccessToken = new Client();

    $options = [
      'headers' => [
        'Accept'     => 'application/json',
      ],
      "form_params" => [
        "grant_type" => "client_credentials", 
        "client_id" => $_ENV["CLIENT_ID"], 
        "client_secret" => $_ENV["CLIENT_SECRET"]
      ]
    ];
    $result = $requestAccessToken->post($_ENV['CLIENT_API_URL'], $options);

    return (string) $result->getBody();
  }
  catch(Exception $error) {
    \Drupal::logger('signup')->error("error " . $error-getMessage());
  }
}

推荐答案

该问题是由于drupal-8中直接支持guzzlehttp引起的,与通过composer安装的软件包发生冲突.

The issue was caused due to guzzlehttp being directly supported in drupal-8, caused a confliction with the package installed via composer.

在删除作曲家的库后,使用以下文档: https://www.drupal.org/docs/8/modules/http-client-manager/introduction

After removing composer libraries for guzzle and use the following documentation: https://www.drupal.org/docs/8/modules/http-client-manager/introduction

这篇关于调用未定义的函数GuzzleHttp \ Psr7 \ get_message_body_summary()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆