记一次通过curl命令使用post请求丢失数据的情况和解决方案
执行命令,提交数据
curl -X POST "http://localhost:8880/api/risk_rule_base/edit" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"is_enabled\": 0, \"rule_id\": 7, \"rule_json\": \"{\\\"sign\\\":\\\"4\\\",\\\"match\\\":{\\\"value\\\":\\\"paysuborder|get::merchandiseid:$merchandiseid:negativeprice:$time\\\"}}\", \"rule_name\": \"测试呀\"}"
{"code":200,"message":"","data":"","trace_id":"ac1064e4601a0b9feb8036d2658221b0","stack":""}
服务接收日志如下
{"level":"info","time":"2021-02-03T10:34:07.948+0800","linenum":"/Users/donghongchen/workspace/shihuituan/bigdata/risktools/middleware/request_log.go:26","msg":"com_request_in {traceId : ac1064e4601a0b9feb8036d2658221b0 , uri : /api/risk_rule_base/edit , method : POST , args : map[] , body : { \"is_enabled\": 0, \"rule_id\": 7, \"rule_json\": \"{\\\"sign\\\":\\\"4\\\",\\\"match\\\":{\\\"value\\\":\\\"paysuborder|get::merchandiseid::negativeprice:\\\"}}\", \"rule_name\": \"测试呀\"} , from : ::1 , Authorization : }","serviceName":"risktools"}
原本的数据为 paysuborder|get::merchandiseid:$merchandiseid:negativeprice:$time
,经过服务后的日志打印为paysuborder|get::merchandiseid::negativeprice:
解决方法
使用 curl -d @data.txt
的方式处理此种情况。
1:新建一个data.txt文件,将要post的json数据写入到data.txt里面
{
"is_enabled": 0,
"rule_id": 7,
"rule_json": "{\"sign\":\"4\",\"match\":{\"value\":\"paysuborder|get::merchandiseid:$merchandiseid:negativeprice:$time\"}}",
"rule_name": "测试呀"
}
2:更改命令为如下即可解决丢失的问题:
curl -X POST http://localhost:8880/api/risk_rule_base/edit -H "accept: application/json" -H "Content-Type: application/json" -d @edit.txt