在 Xamarin 表单 pcl 项目中使用 HttpUtility
Using the HttpUtility in a Xamarin forms pcl project
我正在尝试在我的 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-encoding,System.Net.WebUtility.HtmlEncode
也可以在同一个命名空间中使用。
示例代码
using System.Net;
string postString = String.Format("username={0}&password={1}&grant_type=password",
WebUtility.UrlEncode(username),
WebUtility.UrlEncode(password));
我 运行 遇到了同样的问题,添加对 'System.Net.Http' 的引用对我有用。
我正在尝试在我的 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-encoding,System.Net.WebUtility.HtmlEncode
也可以在同一个命名空间中使用。
示例代码
using System.Net;
string postString = String.Format("username={0}&password={1}&grant_type=password",
WebUtility.UrlEncode(username),
WebUtility.UrlEncode(password));
我 运行 遇到了同样的问题,添加对 'System.Net.Http' 的引用对我有用。