尝试调用名为“ Symfony \ Component \ HttpClient \ CurlHttpClient”的未定义方法“ Create”

时间:2019-08-14 11:53:38

标签: php symfony4

我需要对API使用基本的令牌身份验证,并且我想创建服务来做到这一点(我将在其他控制器中使用这些功能),因此我创建了名为pandas_dict = {0: {0: 'Model:', 1: 'Dependent Variable:', 2: 'Date:', 3: 'No. Observations:', 4: 'Df Model:', 5: 'Df Residuals:', 6: 'Converged:', 7: 'No. Iterations:'}, 1: {0: 'Logit', 1: 'sick_percentage', 2: '2019-08-14 13:32', 3: '28', 4: '2', 5: '25', 6: '0.0000', 7: '35.0000'}, 2: {0: 'Pseudo R-squared:', 1: 'AIC:', 2: 'BIC:', 3: 'Log-Likelihood:', 4: 'LL-Null:', 5: 'LLR p-value:', 6: 'Scale:', 7: ''}, 3: {0: 'inf', 1: '6.0798', 2: '10.0764', 3: '-0.039902', 4: '0.0000', 5: '1.0000', 6: '1.0000', 7: ''}} df = pd.DataFrame(pandas_dict)

的服务

SMSApiService.php

smsapi

由于symfony文档: https://symfony.com/doc/current/components/http_client.html#authentication

我总是会收到错误:

<?php

namespace App\Service;

use Symfony\Contracts\HttpClient\HttpClientInterface;

class SMSApiService
{
    private $httpClient;
    private $apiHost;
    private $apiToken;

    public function __construct(HttpClientInterface $httpClient, $apiToken, $apiHost)
    {
        $this->apiHost = $apiHost;
        $this->apiToken = $apiToken;
        $this->httpClient = $httpClient::Create([    
    'auth_bearer' => $this->apiToken]);
    }

    public function sendSMS()
    {
        $response = $this->httpClient->request('GET', $this->apiHost);
        $statusCode = $response->getContent();
        return $statusCode;
    }
}

我该怎么做才能使用创建方法并输入API凭据? (API令牌)。 Attempted to call an undefined method named "Create" of class "Symfony\Component\HttpClient\CurlHttpClient". 提供了apiHostapiToken

0 个答案:

没有答案