Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UrlEncode through a console application?

Tags:

c#

.net

console

Normally I would just use:

HttpContext.Current.Server.UrlEncode("url"); 

But since this is a console application, HttpContext.Current is always going to be null.

Is there another method that does the same thing that I could use?

like image 622
KevinUK Avatar asked Aug 18 '08 14:08

KevinUK


People also ask

How do I use HttpUtility UrlEncode?

The HttpUtility. UrlEncode method uses UTF-8 encoding by default. Therefore, using the UrlEncode method provides the same results as using the UrlEncode method and specifying UTF8 as the second parameter. UrlEncode is a convenient way to access the UrlEncode method at run time from an ASP.NET application.

What is Server UrlEncode in asp net?

UrlEncode is a convenient way to access the HttpUtility. UrlEncode method at run time from an ASP.NET application. Internally, UrlEncode uses HttpUtility. UrlEncode to encode strings. To encode or decode values outside of a web application, use the WebUtility class.

Do I need to UrlEncode post data?

General Answer. The general answer to your question is that it depends. And you get to decide by specifying what your "Content-Type" is in the HTTP headers. A value of "application/x-www-form-urlencoded" means that your POST body will need to be URL encoded just like a GET parameter string.

What does server UrlEncode do?

The URLEncode method applies URL encoding rules, including escape characters, to a specified string. URLEncode converts characters as follows: Spaces ( ) are converted to plus signs (+). Non-alphanumeric characters are escaped to their hexadecimal representation.


2 Answers

I'm not a .NET guy, but, can't you use:

HttpUtility.UrlEncode Method (String) 

Which is described here:

HttpUtility.UrlEncode Method (String) on MSDN

like image 35
Andrew Taylor Avatar answered Oct 17 '22 09:10

Andrew Taylor


Try this!

Uri.EscapeUriString(url); 

Or

Uri.EscapeDataString(data) 

No need to reference System.Web.

Edit: Please see another SO answer for more...

like image 199
Ostati Avatar answered Oct 17 '22 11:10

Ostati