please tell me how to encode url in httprequest using c#, we we have to paas parameters in url.
like: http://_domain/api/sms/?uid=_uid&pwd=_pwd.
if i hav to pass parameters(_domain,_uid,_pwd) to this string.then how it can be done?
also i want to know that is it necessary to encode it?

Solution 1

The UrlEncode function is used to escape especial characters like '&' and '=' so a parser doesn't consider them as syntax. It takes a string (media type text/plain) and returns a string (media type application/x-www-form-urlencoded).

Encoding.UTF8.GetBytes is used to convert the string (media type application/x-www-form-urlencoded in our case) into an array of bytes, which is what the WebRequest API expects.