Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# Sending requst with special characters interferes the string

I send a request from one project in solution to another:

WebRequest request = WebRequest.Create(UrlTemplate);
request.Timeout = 500000;
request.Method = WebRequestMethods.Http.Post;
request.ContentType = ContentType;
byte[] postData = System.Text.Encoding.ASCII.GetBytes(data);
request.ContentLength = postData.Length;
Stream newStream = request.GetRequestStream();
// Send the data.
newStream.Write(postData, 0, postData.Length);
newStream.Flush();
newStream.Close();

Well, in the function that is set in UrlTemplate I get the correct string, (which I send in the data), but the problem starts when the string contains special characters.

If the string is: 12&34

What I get in the function is: 12.

If the string is: 12+34

What I get in the function is: 12 34.

I'll be glad to know if it has happened to some of you and how you solved it. Thank in advance.

like image 617
ParPar Avatar asked Dec 26 '22 12:12

ParPar


1 Answers

Use System.Web.HttpUtility.UrlEncode or System.Net.WebUtility.UrlEncode while forming UrlTemplate

like image 112
L.B Avatar answered Dec 31 '22 13:12

L.B