Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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?
Posted 27-Dec-12 2:45am
maan_k446
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

For Url Enoding/Decoding you need to use WebUtily class.

To see its details visit: MSDN WebUtility Class[^]
Here check UrlDecode and UrlEncode.

But from what you ask in order to get the parameters that use you should use Request.Querystring. MSDN Request.Querystring[^]
An example usage;
if (Request.QueryString["id"] != null) {
            try
            {
                id = int.Parse(Request.QueryString["id"]);
            }
            catch
            {
                // deal with it
            }
        }

Good luck,
OI
  Permalink  
Comments
maan_k at 27-Dec-12 8:00am
   
actually i want to pass parameters to use api.
Rate this: bad
good
Please Sign up or sign in to vote.

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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Suvendu Shekhar Giri 265
1 Sergey Alexandrovich Kryukov 235
2 Andy Lanng 185
3 PIEBALDconsult 180
4 Black_Rose 130
0 Sergey Alexandrovich Kryukov 6,360
1 OriginalGriff 5,878
2 Peter Leow 2,514
3 Maciej Los 2,263
4 Abhinav S 2,249


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100