FreeSWITCH中文网,电话机器人开发网 ,微信订阅号:



tags:FreeSWITCH修改头 指定代理添 加请求头 响应头 自定义头等 创建时间:2015-12-23 19:52:48


Modifying the To: header You can override the To: header by appending ^. Example 1: sofia/foo/user%^101@$${domain}

Specifying SIP Proxy With fs_path
You can route a call through a specific SIP proxy by using the "fs_path" directive. Example:
Channel Variables

Adding Request Headers
You can add arbitrary headers to outbound SIP calls by prefixing the string 'sip_h_' to any channel variable, for example:
<action application="set" data="sip_h_X-Answer=42"></action>
<action application="bridge" data="sofia/"></action>
Note that for BYE requests, you will need to use the prefix 'sip_bye_h_' on the channel variable.
Informational Tip
While not required, you should prefix your headers with "X-" to avoid issues with interoperability with other SIP stacks.
All inbound SIP calls will install any X- headers into local variables.
This means you can easily bridge any X- header from one FreeSWITCH instance to another.
To access the header above on a 2nd box, use the channel variable ${sip_h_X-Answer}
It is important to note that the syntax ${sip_h_customer-header} can't be used to retrieve any custom header not starting with X-.
It is because Sofia only reads and puts into variables custom headers starting with X-.

Adding Response Headers
There are three types of response header prefixes that can be set:
Response header
Provisional response header
Bye response header
Each prefix will exclusively add headers for their given types of requests - there is no "global" response header prefix that will add a header to all response messages.
For example:
<action application="set" data="sip_rh_X-Reason=Destination Number Not in Footprint"></action>
<action application="set" data="sip_bye_h_X-Accounting=Some Accounting Data"></action>

Adding Custom Headers
For instance, you may need P-Charge-Info to append to your INVITE header, you may do as follows:
<action application="set"><![CDATA[sip_h_P-Charge-Info=<sip:${caller_id_number}@${domain_name}>;npi=0;noa=3]]></action>
Then, you would see it in SIP message:
INVITE sip:19099099099@ SIP/2.0
Via: SIP/2.0/UDP;rport;branch=z9hG4bKyg61X9v3gUD4g
Max-Forwards: 69
From: "DJB" <sip:2132132132@>;tag=XQKQ322vQF5gK
To: <sip:19099099099@>
Call-ID: b6c776f6-47ed-1230-0085-000f1f659e58
CSeq: 30776798 INVITE
Contact: <sip:mod_sofia@>
User-Agent: FreeSWITCH-mod_sofia/1.2.0-rc2+git~20120713T162602Z~0afd7318bd+unclean~20120713T184029Z
Supported: timer, precondition, path, replaces
Allow-Events: talk, hold, conference, refer
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 229
P-Charge-Info: <sip:2132132132@>;npi=0;noa=3
X-FS-Support: update_display,send_info.
Remote-Party-ID: "DJB" <sip:2132132132@>;party=calling;screen=yes;privacy=off
Strip SIP Headers
Strip SIP Headers

Additional Channel variables
Additional variables may also be set to influence the way calls are handled by sofia.
For example, contacts can be filtered by setting the 'sip_exclude_contact' variable. Example:
<anti-action application="set" data="sip_exclude_contact=${network_addr}"></anti>
Or you can perform SIP Digest authorization on outgoing calls by setting sip_auth_username and sip_auth_password variables to avoid using Gateways to authenticate. Example:
<action application="bridge" data="[sip_auth_username=secretusername,sip_auth_password=secretpassword]sofia/external/"></action>
Changing the SIP Contact user FreeSWITCH normally uses mod_sofia@ip:port for the internal SIP contact. To change this to foo@ip:port, there is a variable, sip_contact_user:

上海老李,QQ:1354608370,FreeSWITCH QQ群: