【问题标题】:Using the HttpUtility in a Xamarin forms pcl project在 Xamarin 表单 pcl 项目中使用 HttpUtility
【发布时间】:2018-02-15 15:18:14
【问题描述】:

我正在尝试在我的 Xamarin 表单应用程序中使用 HttpUtility。我有一个 Pcl 项目。这不可能吗?我试图添加 system.web 命名空间,但没有运气。请协助。我怎样才能让它工作。

string postString = String.Format("username={0}&password={1}&grant_type=password", HttpUtility.HtmlEncode(username), HttpUtility.HtmlEncode(password));

【问题讨论】:

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


    【解决方案1】:

    我认为应该是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));
    

    【讨论】:

    • 从 Nuget 包中添加什么。我正在使用 Visual Studio for Mac。
    • 据我所知不需要 nuget 包
    • 那么我如何从我粘贴的代码中使用它呢?没看懂
    【解决方案2】:

    我遇到了同样的问题,添加对“System.Net.Http”的引用对我有用。

    【讨论】:

      猜你喜欢
      • 2018-10-06
      • 2017-03-15
      • 1970-01-01
      • 2018-03-08
      • 1970-01-01
      • 2016-11-14
      • 1970-01-01
      • 2018-03-22
      • 1970-01-01
      相关资源
      最近更新 更多