Convert string to "URL Safe" string for Twilio

This is not Twilio, but the problem is invoking the Twilio API.

I want to create an XML file through Twilio lab:

http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E 

The above URL works fine as a parameter in the API and obviously works if you use your browser to view the output.

I can also see the following in the browser: it works fine, but this version of the URL does not work as a Twilio API parameter

 http://twimlets.com/echo?Twiml=Response><Say>Hi+there.</Say></Response> 

For ease of reading and debugging, I would prefer to have a second URL. Is there a library or other way in C # to convert the second, beautiful URL to the first, replacing% 3C with a '<' character, etc.? I could just make a replacement right before sending it to the API, as my application pushes and stores a nice version everywhere. Of course, I can write it myself to do the conversion, but it looks like this would be a common problem. Thanks!

+6
source share
1 answer

Perhaps this is what you are looking for?

 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); } 

The output is a line without saving:

 http://twimlets.com/echo?Twiml=<Response><Say>Hi+there.</Say></Response> 

And back to normal:

 string encoded = Uri.EscapeDataString(decoded); 

Exit - escaped string:

 http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E 
+15
source

All Articles