我正在尝试在我的 Xamarin 表单应用程序中使用 HttpUtility。我有一个 Pcl 项目。这不可能吗?我尝试添加 system.web 命名空间,但没有成功。请协助。我怎样才能让它发挥作用。
string postString = String.Format("username={0}&password={1}&grant_type=password", HttpUtility.HtmlEncode(username), HttpUtility.HtmlEncode(password));
最佳答案
我相信它应该是System.Net.WebUtility.UrlEncode
编辑 - 1
根据您的代码示例,我相信您的目标是 url 编码 - 您应该使用 System.Net.WebUtility.UrlEncode
;但如果您特别想使用 html 编码,System.Net.WebUtility.HtmlEncode
也可以在同一命名空间中使用。
示例代码
using System.Net;
string postString = String.Format("username={0}&password={1}&grant_type=password",
WebUtility.UrlEncode(username),
WebUtility.UrlEncode(password));
关于c# - 在 Xamarin forms pcl 项目中使用 HttpUtility,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46086958/