简体   繁体   English

Anglesharp和Xamarin.Forms OpenAsync无法在.Droid项目中使用

[英]Anglesharp and Xamarin.Forms OpenAsync does not work in.Droid project

I currently have an application for Android in Java, which I`am rewriting in Xamarin.Forms for the iOS support. 我目前有一个适用于Java的Android应用程序,我正在Xamarin.Forms中重写该应用程序以获取iOS支持。 In the Android app i used Jsoup, and in the Xamarin app i am using AngleSharp. 在Android应用程序中,我使用了Jsoup,在Xamarin应用程序中,我使用了AngleSharp。

I have the issue that the code below works on iOS and UWP, but not in the Droid project. 我遇到的问题是,以下代码可在iOS和UWP上运行,但不能在Droid项目中使用。

My suspicion is that no connection is being made when calling context.OpenAsync(url); 我的怀疑是调用context.OpenAsync(url);时没有建立连接。

I have the 我有

<uses-permission android:name="android.permission.INTERNET" />

in my Android Manifest. 在我的Android清单中。 I am targeting minSdk=17, targetSdk=24. 我的目标是minSdk = 17,targetSdk = 24。 The issue persisists in both the Emulator and on my Galaxy S7. 问题一直存在于模拟器和我的Galaxy S7中。

Code: 码:

try
        {
                var url = "<URL>";
                var configuration = Configuration.Default.WithDefaultLoader().WithCookies();
                var context = BrowsingContext.New(configuration);
                var document = await context.OpenAsync(url);
                IHtmlInputElement username = document.QuerySelector("input[id='username']") as IHtmlInputElement;
                IHtmlInputElement password = document.QuerySelector("input[id='password']") as IHtmlInputElement;
                IHtmlFormElement loginform = document.QuerySelector("form[id='logonForm']") as IHtmlFormElement;

                username.Value = "<uname>";
                password.Value = "<pword>";
                document = await loginform.SubmitAsync();

                Debug.WriteLine(context.Active.Url);
            }
            catch (Exception e)
            {
                Debug.WriteLine("ERROR " + e);
            }

Nb. 铌。 Due to privacy i am not showing the url or the username and password. 由于隐私原因,我没有显示网址或用户名和密码。 Any help is appreciated! 任何帮助表示赞赏!

This is not a problem with AngleSharp, but rather with the Mono stack below. 这不是AngleSharp的问题,而是下面的Mono堆栈的问题。 Make sure you have given the app the necessary permissions. 确保您已授予该应用必要的权限。 Also make sure that potential certificates (if the page is accessed via HTTPS) are accepted. 另外,请确保接受了潜在的证书(如果通过HTTPS访问该页面)。 Android will deny requests that do not fit the permission model (eg, app does not have permission, self-signed certificates that are not installed, ...). Android将拒绝不符合权限模型的请求(例如,应用程序没有权限,未安装自签名证书,...)。

Hope this helps! 希望这可以帮助! (unfortunately, the exact issue for the question was never found / communicated - see corresponding GitHub issue ). (不幸的是,从未找到/传达过该问题的确切问题-请参阅相应的GitHub问题 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin.Forms 不编译 Android 项目 - Xamarin.Forms does not compile an Android Project Xamarin表单:使用Visual Studio在Droid项目中出错 - Xamarin Forms: error in Droid project with Visual Studio Xamarin.Forms Droid 上的 MSAL 中未找到 AuthenticationContinuationHelper 类 - AuthenticationContinuationHelper class not found in MSAL on Xamarin.Forms Droid Xamarin.Forms(droid build)MultiDex选项导致应用程序崩溃 - Xamarin.Forms (droid build) MultiDex option causes app to crash Xamarin.Forms Visual Studio 2017项目未部署 - Xamarin.Forms Visual Studio 2017 project does not deploy 使用Xamarin.Forms上的AppCompat在API 22中调整调整大小不起作用 - Adjust resize does not work in API 22 with AppCompat on Xamarin.Forms Xamarin.Forms MasterDetailPage 是否适用于 Kindle VoiceOver 辅助功能 - Does Xamarin.Forms MasterDetailPage work with Kindle VoiceOver accessibility 使用Xamarin.Forms时,Xamarin.Droid在Visual Studio 2015中导致生成错误 - Xamarin.Droid causing build errors in Visual Studio 2015 when using Xamarin.Forms 在Xamarin表单droid项目中的导航栏上显示母版页 - display master page over navigation bar in xamarin forms droid project 使用Xamarin.Forms / Xamarin.Droid进行可切换全屏,稳定布局 - Toggleable fullscreen with stable layout using Xamarin.Forms/Xamarin.Droid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM