Blogger Information
Blog 110
fans 0
comment 0
visits 112319
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Linux-shell-curl-put命令变量及换行问题报错和解决讲解
Coco
Original
1387 people have browsed it

  1. 最近在使用shell curl自动处理ETL时,需要定时触发一API,使用方式为PUT,但是多次触发均失败,命令如下:

  curl -g -i -H "Content-type: application/json" \

  -X PUT "101.201.81.101:8080/preaggregate" \

  -d

  '{"taskId":"base_analyses","aggId":"5bebf84c339e8b79dc018d","WindowId":"662401807f9198d7d5","force":true,"type":"range","dayRanges":[${startdate},${enddate}]}'

  请求结果报错

  原因:

  1.自动换行多了一个 "

  ",原因是json太长,unix会自动换行,换行发送json后,会在json内自动加上该换行符,api解析json会出错,解决该问题的办法就是先定义变量值;

  put_pre='{"taskId":"base_analyses","aggId":"5bebf84c339e8b79dc018d","WindowId":"662401807f9198d7d5","force":true,'

  2.变量使用方式不正确,json内不应该出现${startdate},${enddate}这样的变量,应该改为'xxx'${startdate}'xxx'。

  整理后的正确请求方式为:

  curl -g -i -H "Content-type: application/json" \

  -X PUT "101.201.81.101:8080/preaggregate" \

  -d

  ${put_pre}'"type":"range","dayRanges":['${startdate}','${enddate}']}'

  大家在使用过程中可能也会遇到以上问题,使用这种方式处理即可。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post