问题描述
我正在尝试将一些表单数据从 Code Engine ping subscription 传递到我的应用程序。在创建命令中,我尝试了不同的方法来将数据作为 POST 请求的一部分传递,但是当 ping 事件触发时,它在运行时导致了错误的参数。
ibmcloud ce sub ping create -n tweety --destination twitterbot --path /tweet
--schedule '07 4,8,13,17 * * *' --data 'SECRET_KEY=SET_YOUR_SECRET'
ibmcloud ce sub ping create -n tweety --destination twitterbot --path /tweet
--schedule '07 4,17 * * *' --data '{"SECRET_KEY":"SET_YOUR_SECRET"}'
如何将数据作为常规文本数据而不是 JSON 传递?
解决方法
我花了一段时间才弄明白。 The CLI command allows to pass --content-type
。文档中有示例 application/json。对于常规数据,它将是表单数据和 urlencoded。以下工作,即使用application/x-www-form-urlencoded:
ibmcloud ce sub ping create -n tweety --destination twitterbot --path /tweet
--schedule '07 4,8,13,17 * * *' --data 'SECRET_KEY=SET_YOUR_SECRET'
--content-type 'application/x-www-form-urlencoded'
,
CLI 现在支持非 json:
ibmcloud ce sub ping create -n pinger --data "hello" -d myapp
会对身体产生这样的结果:
你好