将Web内容集成到桌面Java应用程序中

时间:2016-06-24 09:02:40

标签: java javafx safari recaptcha

我想拥有一个在桌面应用中打开网站的平台。我按照指南使用JavaFX public static async Task<bool> SaveSetting(string Key, Object value) { var ms = new MemoryStream(); DataContractSerializer serializer = new DataContractSerializer(value.GetType()); serializer.WriteObject(ms, value); await ms.FlushAsync(); ms.Seek(0, SeekOrigin.Begin); StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(Key, CreationCollisionOption.ReplaceExisting); using (Stream fileStream = await file.OpenStreamForWriteAsync()) { await ms.CopyToAsync(fileStream); await fileStream.FlushAsync(); } return true; } 来显示网站并成功了。

public async static Task<Feed> ReadSetting<type>(string Key)
        {
            var rr = new Feed();

            try
            {
                var ms = new MemoryStream();
                DataContractSerializer serializer = new DataContractSerializer(typeof(type));

                StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(Key);
                using (IInputStream inStream = await file.OpenSequentialReadAsync())
                {
                    rr.ArticlesList = (type)serializer.ReadObject(inStream.AsStreamForRead());
                }
            }
            catch (FileNotFoundException)
            {

            }
            return rr;
        }

但是当它显示谷歌的reCaptcha v2时我被卡住了:

Image

它说升级浏览器。我尝试通过加载whoer extend检查版本,它显示我正在使用safari 2.0:

Image

我需要帮助才能在我的WebEngine中显示这个rec​​aptcha,或者是否有任何其他解决方案可以使用reCaptcha显示网站,但此JavaFX仍然可以。

1 个答案:

答案 0 :(得分:4)

将用户代理设置为模拟常用浏览器,例如Safari 9.1.1:

webEngine.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/601.6.17 (KHTML, like Gecko) Version/9.1.1 Safari/601.6.17");