我遇到类似这样的问题:https://forums.xamarin.com/discussion/6319/problem-with-webview-and-url
使用UIWebView
,我尝试传递带有查询字符串的网址。 URI如下所示:"Content/Content/holder.html/?contentpath=/test.html"
如果没有查询字符串,文档会正确显示。但是,使用查询字符串,我收到以下错误:
Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server."
好像它没有将查询字符串分开 我已经阅读了一些C解决方案,但我无法在C#解决方案中反映出来;特别
NSString *URLString = [url absoluteString];
NSString *queryString = @"?param1=1";
NSString *URLwithQueryString = [URLString stringByAppendingString: queryString];
答案 0 :(得分:1)
在这里找到我的答案: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));