【问题标题】:Why isn't this urlencode JSON GET request working?为什么这个 urlencode JSON GET 请求不起作用?
【发布时间】:2018-04-10 10:43:58
【问题描述】:
$word = $_GET['search'];
$json = json_encode('{"query":{"match":{"name":"'.$word.'"}}}');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://10.128.0.2:9200/testers/test/_search' . urlencode($json));
$resp = curl_exec($curl);

$word 是从 URL 填充的,这工作正常。 $resp 没有返回任何价值。 'name' 是弹性搜索字段的名称。

我正在使用 PHP 来运行这个 curl 请求 as per elasticserch,除了所有在一个 URL 中。有没有更好的方法从 PHP 代码中做到这一点?

【问题讨论】:

    标签: php json curl elasticsearch get


    【解决方案1】:

    如果您使用 GET 调用,则需要在 source 查询字符串参数中传递查询:

    curl_setopt($curl, CURLOPT_URL, 'http://10.128.0.2:9200/testers/test/_search?source=' . urlencode($json));
    

    【讨论】:

      猜你喜欢
      • 2018-06-05
      • 1970-01-01
      • 2020-10-15
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 2021-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多