gpt4 book ai didi

php - ElasticSearch/ElasticCloud-连接被拒绝

转载 作者:行者123 更新时间:2023-12-02 23:53:14 24 4
gpt4 key购买 nike

我正在尝试使用ElasticSearch的托管解决方案,但似乎无法连接到端点。

我得到的只是以下内容:

Failed to connect to xxx port 9243: Connection refused

这是我的代码...
class ElasticSearchApi {

protected $endpoint;
protected $auth;
protected $curl;

public function __construct() {

$this->endpoint = 'https://myendpoint.com:9243';
$this->auth = 'elastic:pass';

}

public function getIndices() {

$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_URL, $this->endpoint);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'accept: application/json', 'Authorization: Basic '. base64_encode($this->auth)));
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false);

$responseData = curl_exec($this->curl);
if(curl_errno($this->curl)) {
return curl_error($this->curl);
}
curl_close($this->curl);

return $responseData;
}

}

最佳答案

我会先尝试以下cURL选项:

curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

连接被拒绝很有趣。如果您在 shell 上使用带有 curl 的细节,那行得通吗?

还有没有特定原因导致您不使用官方的 PHP client吗?重试,重新建立联系,...将使您的生活变得更加轻松。

关于php - ElasticSearch/ElasticCloud-连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56040310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com