UrlEncode through a console application?

后端 未结 12 1250
我寻月下人不归
我寻月下人不归 2020-12-15 02:16

Normally I would just use:

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

But since this is a console application, HttpContext.Curren

相关标签:
12条回答
  • 2020-12-15 03:07

    Best thing is to Add Reference to System.web..dll

    and use var EncodedUrl=System.Web.HttpUtility.UrlEncode("URL_TEXT");

    You can find the File at System.web.dll

    0 讨论(0)
  • 2020-12-15 03:10

    Kibbee offers the real answer. Yes, HttpUtility.UrlEncode is the right method to use, but it will not be available by default for a console application. You must add a reference to System.Web. To do that,

    1. In your solution explorer, right click on references
    2. Choose "add reference"
    3. In the "Add Reference" dialog box, use the .NET tab
    4. Scroll down to System.Web, select that, and hit ok

    NOW you can use the UrlEncode method. You'll still want to add,

    using System.Web

    at the top of your console app or use the full namespace when calling the method,

    System.Web.HttpUtility.UrlEncode(someString)

    0 讨论(0)
  • 2020-12-15 03:11

    Try this!

    Uri.EscapeUriString(url);
    

    Or

    Uri.EscapeDataString(data)
    

    No need to reference System.Web.

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

    0 讨论(0)
  • 2020-12-15 03:13

    use the static HttpUtility.UrlEncode method.

    0 讨论(0)
  • 2020-12-15 03:16

    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

    0 讨论(0)
  • 2020-12-15 03:16

    HttpUtility.UrlEncode("url") in System.Web.

    0 讨论(0)
提交回复
热议问题