UrlEncode / System.Web在控制台应用程序中不可用?

时间:2010-07-15 16:40:36

标签: .net reference urlencode

我的申请表中需要UrlEncode,因为我正在向我的服务器提交表单。我的应用程序是一个针对.NET 3.5的快速控制台实用程序。

该页面说我需要System.Web程序集,但当我尝试添加引用它不在那里。我的WebServer应用程序有它,它也针对3.5,但这个控制台应用程序无法引用它。为什么不?我如何访问UrlEncode?

1 个答案:

答案 0 :(得分:2)

您可以 - 只需确保添加了对System.Web.dll的引用,默认情况下可能不在控制台项目中。

我怀疑这不在客户档案中,请注意 - 我不知道这对你来说是不是一个问题。

我刚从命令行使用控制台应用测试了这个:

using System;
using System.Web;

class Test
{
    static void Main()
    {
        string text = "hello there";
        string encoded = HttpUtility.UrlEncode(text);
        Console.WriteLine(encoded); // prints hello+there
    }
}

我能够用

编译
csc Test.cs

但我怀疑默认响应文件比Visual Studio中的默认控制台应用程序项目模板包含更多的程序集引用...