这不是Twilio特有的,但问题确实导致Twilio API调用失败.
我想通过Twilio的实验室生成一个XML文件:
http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E
Run Code Online (Sandbox Code Playgroud)
上面的URL非常适合作为API中的参数,如果您使用浏览器查看输出,这显然有效.
我也可以在浏览器中查看以下内容,它工作正常,但此版本的URL无法作为Twilio API的参数
http://twimlets.com/echo?Twiml=Response><Say>Hi+there.</Say></Response>
Run Code Online (Sandbox Code Playgroud)
为了便于阅读和调试,我更倾向于使用第二个URL.C#中是否有库或其他方式将第二个漂亮的URL转换为第一个,用'<'字符替换%3C等等?然后,我可以在将其发送到API之前立即进行替换,因为我的应用程序推送并在其他地方存储漂亮的版本.我当然可以自己写一个来进行转换,但似乎这是一个常见的问题.谢谢!
Han*_*año 22
这可能是你在找什么?
private void Form1_Load(object sender, EventArgs e)
{
string encoded = "http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E";
string decoded = Uri.UnescapeDataString(encoded);
}
Run Code Online (Sandbox Code Playgroud)
输出 - 非转义字符串:
http://twimlets.com/echo?Twiml=<Response><Say>Hi+there.</Say></Response>
Run Code Online (Sandbox Code Playgroud)
并恢复正常:
string encoded = Uri.EscapeDataString(decoded);
Run Code Online (Sandbox Code Playgroud)
输出 - 转义字符串:
http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E
Run Code Online (Sandbox Code Playgroud)