Tile38 HTTP请求执行AND操作时&&参数报错的解决求助
Tile38 HTTP请求含AND操作查询的格式修正
问题场景
在Tile38中执行带AND(&&)操作的查询时,CLI命令可正常运行,但通过curl发起HTTP请求时,出现「无效参数'&&'」的错误。
正常运行的CLI命令
within evidence where 'timestamp >= 1654128000 && timestamp <= 1658361600' get areas indonesia-aceh
出错的curl请求
curl --location 'localhost:9851' \ --header 'Content-Type: text/plain' \ --data 'within evidence where '\''timestamp >= 1654128000 && timestamp <= 1658361600'\'' get areas indonesia-aceh'
问题原因
出错的核心是shell对&&的解析干扰:原curl命令的引号转义方式导致&&没有被完整包裹在请求体中,被shell当作命令分隔符处理,而非Tile38查询语句的一部分。
修正后的curl请求
你可以采用以下两种正确的格式:
方式一:用双引号包裹整个请求体
将--data的内容用双引号包裹,内部单引号直接保留,&&无需额外转义:
curl --location 'localhost:9851' \ --header 'Content-Type: text/plain' \ --data "within evidence where 'timestamp >= 1654128000 && timestamp <= 1658361600' get areas indonesia-aceh"
方式二:正确转义单引号并包裹完整请求体
如果坚持用单引号包裹--data内容,需将内部的单引号用两个单引号转义,确保整个查询语句被shell识别为单一字符串:
curl --location 'localhost:9851' \ --header 'Content-Type: text/plain' \ --data 'within evidence where '\''timestamp >= 1654128000 && timestamp <= 1658361600'\'' get areas indonesia-aceh'
注:这种写法下,shell会把''解析为单个单引号,最终发送给Tile38的请求体与CLI命令完全一致。
验证逻辑
修正后,curl会将完整的查询语句(包括&&)作为请求体发送给Tile38,Tile38就能正确解析&&作为查询的AND逻辑操作符,而非将其识别为无效参数。
内容的提问来源于stack exchange,提问作者Budi Rahmawan
相关产品推荐
相关产品推荐

