c# - 将带有 QueryString 的 URL 传递给 UIWebView

标签 c# ios xamarin

我遇到了类似的问题:https://forums.xamarin.com/discussion/6319/problem-with-webview-and-url

使用 UIWebView,我试图传递带有查询字符串的 URL。 URI 如下所示:"Content/Content/holder.html/?contentpath=/test.html"

没有查询字符串,文档显示正确。但是,对于查询字符串,我收到以下错误:
Error Domain=NSURLErrorDomain Code=-1100 “在此服务器上找不到请求的 URL。”

它似乎没有分隔查询字符串。
我已经阅读了一些 C 解决方案,但我无法在我的 C# 解决方案中反射(reflect)出来;特别是

NSString *URLString = [url absoluteString];   
NSString *queryString = @"?param1=1"; 
NSString *URLwithQueryString = [URLString stringByAppendingString: queryString];  

最佳答案

在这里找到我的答案:https://forums.xamarin.com/discussion/10444/uiwebview-loadrequest-encoding-url-so-becomes-3f

UIWebView 不喜欢 URL 中的空格:

var escapedBundlePath = Uri.EscapeUriString(NSBundle.MainBundle.BundlePath);
var myUrl = "Path/To/File/Test.html?var1=hello&var2=world";
var nsUrl = new NSUrl(Path.Combine(escapedBundlePath, myUrl));

WebView.LoadRequest(new NSUrlRequest(nsUrl));

关于c# - 将带有 QueryString 的 URL 传递给 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34066575/

相关文章:

c# - MEF 组合问题,多线程

java - 从 C# System.TimeZone 创建 java.util.Date

C# XAML WPF 在 UserControl 上呈现之前使用参数

ios - 从数组设置自定义UITableViewCell的文本

ios - 如何在完成 block 中返回值

iOS - 为什么我不能以相同的方式使用 pushViewController 两次?

c# - 从从 api 填充的 ListView 行单击中提取数据

c# - MonoDroid 和 MonoTouch 的共享库

c# - 从父 View xaml 设置子控件 View 模型的属性

android - 显示 OptionsMenu 时出现 NullPointerException