坑爹的curl: Required request body is missing : post 请求体 不能包含汉字!

时间:2022-10-30 22:58:00

发送curl 请求:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/html' -d '{ \
"body": { \
"account": "41557558612310085632", \
"appid": "5000000002", \
"amount": 12350, \
"paypalAccountEmail": "test%40qq.com", \
"remark": "asd测试" \
} \
}' 'https://mwtest.luo.cn/pp/withdraw/toPaypal'


各种curl 请求错误

竟然出现了各种错误:

2022-09-06 20:17:06,670 ERROR [tp-nio-9040-exec-5] c.h.k.f.web.GlobalExceptionHandler   - [SYSTEM]: Unexpected exception occur at requesting uri /withdraw/detail. nestException ==>> {}
org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public com.luo.lk.framework.data.GenericRspDTO<com.luo.lk.dto.withdraw.WithdrawDetailRspDTO> c
om.luo.lk.controller.WithdrawController.detail(com.luo.lk.framework.data.GenericDTO<com.luo.lk.dto.withdraw.WithdrawDetailReqDTO>)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:160)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:131)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:884)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:858)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)


{"id":"WH-2Y204968NM308944P-1NU002828K214274V","event_version":"1.0","create_time":"20
22-09-06T12:59:07.504Z","resource_type":"payouts","event_type":"PAYMENT.PAYOUTSBATCH.SUCCESS","summary":"Payouts batch completed successfully.","resource":{"batch_header":{"payout_batch_id":"VTR3X5SEE6374","batch_status":"SUCCESS","time_created":"2022-09-06T12:58:57Z","time_completed":"2022-09-06T12:58:59Z","time_closed":"2022-09-06T12:58:59Z","sender_batch_header":{"sender_batch_id":"Test_sdk_rRaPmFR"},"funding_source":"BALANCE","amount":{"currency":"USD","value":"499.00"},"fees":{"currency":"USD","value":"9.98"},"payments":1},"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payouts/VTR3X5SEE6374","rel":"self","method":"GET","encType":"application/json"}]},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2Y204968NM308944P-1NU002828K214274V","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2Y204968NM308944P-1NU002828K214274V/resend","rel":"resend","method":"POST"}]}


改成:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/html' -d '{ 
"body": {
"account": "41557558612310085632",
"appid": "5000000002",
"amount": 12350,
"paypalAccountEmail": "test@qq.com",
"remark": "asd测试"
}
}' 'https://mwtest.l.cn/pp/withdraw/toPaypal'


改成这样:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"body":{"account":"41557558612310085632","appid":5000000002","amount":12350,"orderNo":"WITHDRAW2022081917180700000003"}}' 'https://mwtest.luo.cn/pp/withdraw/detail'

curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/html' -d '{"body": {"account": "41557558612310085632","appid": "5000000002","amount": "12350","paypalAccountEmail": "test@qq.com","remark": "asd测试"}}' 'https://mwtest.luo.cn/pp/withdraw/toPaypal'


百思不得其解

发现还是不行:

Caused by: com.alibaba.fastjson.JSONException: not match : - ", info : pos 69, line 1, column 70{"body":{"account":"41557558612310085632","appid":5000000002","amount":12350,"orderNo":"WITHDRAW2022081917180700000003"}}


始终提示:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/html' -d '{"body": {"account": "41557558612310085632","appid": "5000000002","amount": 123500,"paypalAccountEmail": "test@qq.com","remark": "asd测试"}}' 'https://mwtest.luo.cn/pp/withdraw/toPaypal'


真实奇了怪了啊, 不会 我可是用了十几年的curl 老程序员的呢..  简直怀疑人生了, 


基准测试, 发现原因

后面各种减法测试/基准测试, 发现这个却是ok的:

"body": {  
"account": "41557558612310085632",
"appid": "5000000002",
"amount": 5000000,
"paypalAccountEmail": "sb-kd9ji20394289@personal.example.com",
"remark": "sb-kd9ji20394289@personal.example.com2222222"
}
}' 'https://mwtest.luo.cn/pp/withdraw/toPaypal'


始终不得其解:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/html' -d  '{"body":{"remark":"as我d"}}' 'https://mwtest.luo.cn/pp/withdraw/toPaypal'


后面 只能一个个的测试, 一个个的去掉, 加上的方式, 排除, 终于发现了是 汉字的原因! ! 



后面测试发现 tab 空格也是不行的 !

为什么不能包含汉字? 

坑爹的curl: Required request body is missing : post 请求体 不能包含汉字!


难道是这个  git bash 不支持?

另外发现  有时候新增空行( 回车键的方式), 会导致命令断开:

坑爹的curl: Required request body is missing : post 请求体 不能包含汉字!


why ?  应该是 \n 和 \n\r 的区别