freeswitch的mod_curl模块

乎语百科 207 0

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="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接口,需要注意什么地方。

空空如常

求真得真

标签:

留言评论

  • 这篇文章还没有收到评论,赶紧来抢沙发吧~