我正在尝试在 guzzlehttp 中执行 CURL 获取请求以检查用户是否存在于 CRM 中。每当我尝试执行请求时,标题中都会出现以下错误,我无法在线找到任何资源来解决这个特定问题。任何想法都会非常有帮助,如果您需要任何其他信息,请在评论中告诉我。
包含的软件包:
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));
}
}
}
我有一个发布请求功能来获得一个正常工作的访问令牌。
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"]
]
];
慕娘9325324