c# - 在 Xamarin forms pcl 项目中使用 HttpUtility

标签 c# xamarin.forms portable-class-library

我正在尝试在我的 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/

相关文章:

c# - Debug.Assert 和 Debug.Fail 是否应该自由使用,是否应该留在生产代码中?

c# - 滚动时在 Panel 中平滑绘制或绘制子控件

c# - Lync UCMA SDK Server - 全局订阅所有 Presentities 的状态更新

c# - 使用可移植类库 (PCL) 从 URL 下载字符串

c# - 处理与自定义 bool 类型的比较?

c# - 通过 SSL 保护 Xamarin.Forms 应用程序流量

c# - 为什么我的自定义 ButtonRenderer 不工作?

xaml - 在 Xamarin.Forms 中将 HeightRequest 设置回 Auto

c# - 类型或命名空间名称 'Http' 不存在?

windows-store-apps - 类型 'System.Object' 在未引用的程序集中定义 - Windows 应用商店应用程序