windows下执行curl请求:
curl -H "Content-Type: application/json" http://192.168.160.49:9200/index_partners/_search?pretty -d '{"query":{"match_all":{}},"_source":["id","companyName","targetCompanyId","targetTenantId"],"from":0,"size":100}'
直接报错:"Unexpected character (''' (code 39)): expected a valid value (JSON String, Number, Array, Object, 'true' or 'false')\n at [Source: (org.elasticsearch.common.io.stream.InputStreamStreamInput); line: 1, column: 2]",具体报错信息截图如下:
同样的请求,在Linux下执行却是成功的。截图如下:
问题分析:
在windows命令行里执行上述curl请求,执行报错,因为windows系统里不能识别单引号',得换成双引号",换成双引号后再执行,还是报错,这时还得把请求参数里的"转义成\"。成功截图如下:
所以最终windows下能正确的执行curl命令为
curl -H "Content-Type: application/json" http://192.168.160.49:9200/index_partners/_search?pretty -d "{\"query\":{\"match_all\":{}},\"_source\":[\"id\",\"companyName\",\"targetCompanyId\",\"targetTenantId\"],\"from\":0,\"size\":100}"