You should use HttpUtility.UrlEncode
String _messageString = "message=" + HttpUtility.UrlEncode(TextBox.Text);
http://msdn.microsoft.com/pl-pl/library/system.web.httputility.urlencode.aspx
Question
I have rather very basic question. I would like to send a formated Text from WPF Multiline Textbox to Web application over HttpWebRequest. Till now I've managed to send plain text, so the connection is working.
As an example, I've created a WPF window with Multiline Textbox and Button in it. When, I press button I would like send the Textbox.Text to WebRequest, but this text should be formated (support breaklines, bold, inclined etc).
String _messageString = "message=" + TextBox.Text;
//create authentication string
Byte[] _outBuffer = Encoding.UTF8.GetBytes(_messageString ); //store in byte buffer
I've narrowed down with Fiddler that the format should be something like this:
message=Contrary+to+popular+belief%2C&edttmessage=1
So, my question is, how can I transform the Textbox.Text to the above format? Or is there another way do that I should do it? Thank you in advance.
Solution
You should use HttpUtility.UrlEncode
String _messageString = "message=" + HttpUtility.UrlEncode(TextBox.Text);
http://msdn.microsoft.com/pl-pl/library/system.web.httputility.urlencode.aspx