我正在尝试使用IBM OpenWhisk。它有自己的CLI,但我想使用curl调用一个简单的"echo“示例。
curl -d-data '{"message": "hellow world"}' https://user:password@openwhisk.ng.bluemix.net:443/api/v1/namespaces/whisk.system/action/samples/echo
curl: (6) Couldn't resolve host '"message": "hello world"'
{
"error": "HTTP method not allowed, supported methods: GET",
"code": 81107
}如何通过curl或类似工具调用OpenWhisk,如何进行身份验证?
发布于 2016-03-11 14:58:31
身份验证是通过Basic Authentication完成的,因此您可以在curl中使用-u标志。使用user:pass@url版本,就像您使用的那样,应该也能工作。
要调用一个操作,您必须使用POST,因此使用-XPOST。而且,API期望application/json作为内容类型。数据以卷曲的形式通过-d标志发送。
你的网址上也有一个错误。您需要使用actions而不是action (整个API使用复数)。
总而言之,您的请求应该如下所示:
curl -XPOST -H "Content-Type: application/json" -d '{"message": "hello world"}' -u $USERNAME:$PASSWORD https://openwhisk.ng.bluemix.net/api/v1/namespaces/whisk.system/actions/samples/echo有一个关于这个主题的blog article。对于阻塞操作,只需添加?blocking=true作为参数即可。
发布于 2016-03-11 16:55:05
wsk还有一个非常方便的"-v“选项,它向您显示和headers,如果您这样做的话:
wsk -v action invoke hello --blocking您将看到实际的REST调用。
https://stackoverflow.com/questions/35943185
复制相似问题