简体   繁体   English

IBM Cloud Code Engine:如何在 ping 订阅中传递非 JSON 数据?

[英]IBM Cloud Code Engine: How to pass non-JSON data in ping subscription?

I am trying to pass some form data to my app from a Code Engine ping subscription .我正在尝试将一些表单数据从代码引擎 ping 订阅传递到我的应用程序。 In the create command, I have tried different methods to pass the data as part of the POST request, but it resulted in wrong parameters at runtime when the ping event fired.在创建命令中,我尝试了不同的方法来将数据作为 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,8,13,17 * * *' --data '{"SECRET_KEY":"SET_YOUR_SECRET"}' 

How can I pass the data as regular text data, not as JSON?如何将数据作为常规文本数据而不是 JSON 传递?

I took a while to figure it out.我花了一段时间才弄清楚。 The CLI command allows to pass --content-type . CLI 命令允许传递--content-type In the documentation is the example application/json .文档中是示例application/json For regular data, it would be form data and urlencoded.对于常规数据,它将是表单数据和 urlencoded。 The following works, ie, using application/x-www-form-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'

The CLI does support non-json now: CLI 现在确实支持非 json:

ibmcloud ce sub ping create -n pinger --data "hello" -d myapp ibmcloud ce sub ping create -n pinger --data "hello" -d myapp

will results in this for the body:将导致这个身体:

hello你好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM