freeswitch的mod_curl模块


freeswitch的mod_curl模块

文章插图
概述有时候,我们需要在呼叫的过程中,或过程后调用web api接口 。
freeswitch的mod_curl模块可以很方便的实现web api的接口调用 。
mod_curl模块默认不安装 , 需要进入模块目录自行编译安装,并配置modules.conf.xml文件在fs启动时加载模块 。
<load module="mod_curl"/>
环境centos:CentOS 7
freeswitch:v1.10.7
GCC:4.8.5
API接口api接口格式 。
curl url [headers|json|content-type <mime-type>|connect-timeout <seconds>|timeout <seconds>] [get|head|post|delete|put [data]]
APP接口app接口格式 。
<action application="curl" data="https://www.huyubaike.com/biancheng/url [headers|json] [get|head|post [url_encode_data]]"/>
测试实例freeswitch@localhost.localdomain> curl http://10.55.55.137:8080/cb content-type application/json;charset=utf-8 connect-timeout 1 timeout 1 post '{"test":"1234","duration":15}'
2022-11-09 16:00:54.288442 [DEBUG] mod_curl.c:200 method: post, url: http://10.55.55.137:8080/cb, content-type: application/json;charset=utf-8
2022-11-09 16:00:54.288442 [DEBUG] mod_curl.c:252 Post data: {"test":"1234","duration":15}
{"status":0}
freeswitch@localhost.localdomain> curl http://10.55.55.137:8080/cb content-type application/json;charset=utf-8 connect-timeout 1 timeout 1 json post '{"test":"1234","duration":15}'
2022-11-09 16:02:31.008475 [DEBUG] mod_curl.c:200 method: post, url: http://10.55.55.137:8080/cb, content-type: application/json;charset=utf-8
2022-11-09 16:02:31.008475 [DEBUG] mod_curl.c:252 Post data: {"test":"1234","duration":15}
{"status_code":"200","body":"{\"status\":0}","version":"HTTP/1.0","phrase":"OK","headers":[{"key":"Server","value":"BaseHTTP/0.6 Python/3.10.7"},{"key":"Date","value":"Wed, 09 Nov 2022 08:02:31 GMT"},{"key":"Content-Type","value":"application/json;charset=utf-8"}]}
其中第二条带了“json”参数,返回值的code、header和消息体统一?变更为json格式 。
总结简单的web api接口调用可以直接使用mod_curl模块接口 。
如果需要在定时任务中调用curl接口,需要注意什么地方 。
空空如常
求真得真
【freeswitch的mod_curl模块】

    推荐阅读