分享一个最近使用Elasticsearch-PHP 2.0 碰到的问题。tp3.1.3报错 Content-Type header [] is not supported。
找了很多方法,没有效果,最后跟着源码发现:
修改 vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php 这个文件
if (isset($hostDetails['user']) && isset($hostDetails['pass'])) {
$connectionParams['client']['curl'][CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
$connectionParams['client']['curl'][CURLOPT_USERPWD] = $hostDetails['user'].':'.$hostDetails['pass'];
}
在这行段代码后面加上:
$connectionParams['client']['curl'][CURLOPT_HTTPHEADER] = ['Accept: application/json', 'Content-Type: application/json'];
测试一下ok。