我正在尝试使用以下方法对 URL 进行编码HttpUtility.UrlEncode()
方法,为什么我得到
命名空间“System.Web”中不存在类型或命名空间名称“HttpUtility”(是否缺少程序集引用?)
错误 ?
我正在使用 Visual C# 2008 Express 版。
我使用的代码很简单:
using System;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Web;
namespace Lincr
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void cmdShorten_Click(object sender, EventArgs e)
{
WebRequest wrURL;
Stream objStream;
wrURL = WebRequest.Create("http://lin.cr?l=" + System.Web.HttpUtility.UrlEncode(txtURL.Text) + "&mode=api&full=1");
objStream = wrURL.GetResponse().GetResponseStream();
StreamReader objSReader = new StreamReader(objStream);
textBox1.Text = objSReader.ReadToEnd().ToString();
}
}
}
您需要包含对System.Web
。在解决方案资源管理器中右键单击您的项目并选择添加参考...。如果你看一下MSDN http://msdn.microsoft.com/en-us/library/system.web.httputility.aspx你会看到它包含在System.Web.dll
程序集,据我记得,在新项目中默认情况下不会引用它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)