2017-07-04 34 views
7

में Google में साइन इन नहीं कर सकता मैं जावाएफएक्स वेबव्यू में Google में साइन इन नहीं कर सकता। जब मैं 'अगला' बटन क्लिक करता हूं तो पृष्ठ लोड नहीं होता है।जावाएफएक्स वेबव्यू

विभिन्न वेबसाइटों पर अन्य लॉग इन ठीक काम करते हैं।

यहाँ एक उदाहरण है आप चला सकते हैं:

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.layout.StackPane; 
import javafx.scene.web.WebEngine; 
import javafx.scene.web.WebView; 
import javafx.stage.Stage; 

public class App extends Application 
{ 
    @Override 
    public void start(Stage primaryStage) throws Exception 
    { 
     WebView browser = new WebView(); 

     WebEngine webEngine = browser.getEngine(); 

     webEngine.load("https://calendar.google.com"); 

     StackPane root = new StackPane(); 
     root.getChildren().add(browser); 

     primaryStage.setScene(new Scene(root, 600, 600)); 
     primaryStage.show(); 
    } 

    public static void main(String[] args) 
    { 
     launch(args); 
    } 
} 

Screenshot here

उत्तर

7

लघु संस्करण: इससे पहले कि आप पृष्ठ लोड

आपका मुख्य विधि में निम्न पंक्ति जोड़ें,:

System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); 

लांग संस्करण:

मेरी पहली वृत्ति है कि जावास्क्रिप्ट काम नहीं कर रहा था, लेकिन मैं डमी ईमेल परीक्षण किया है और सही ढंग से त्रुटि मिली:

Couldn't find your Google Account

तो यह कुछ जावास्क्रिप्ट तरह लग रहा था काम कर रहा था, लेकिन नहीं वह हिस्सा जिसने उपयोगकर्ता को अपना पासवर्ड दर्ज करना जारी रखा। मैं सांत्वना त्रुटियों के लिए सुनने के लिए निम्न श्रोता कहा, which I found here:

com.sun.javafx.webkit.WebConsoleListener.setDefaultListener(
    (webView, message, lineNumber, sourceId) -> 
     System.out.println("Console: [" + sourceId + ":" + lineNumber + "] " + message) 
); 

यह निम्न त्रुटि के परिणामस्वरूप:

Console: [null:0] XMLHttpRequest cannot load https://ssl.gstatic.com/accounts/static/_/js/blahblahblah
Origin https://accounts.google.com is not allowed by Access-Control-Allow-Origin.

यह एक सुरक्षा सुविधा Same-Origin Policy कहा जाता है। यह संभावित रूप से दुर्भावनापूर्ण तृतीय-पक्ष वेबसाइटों से स्क्रिप्ट लोड करने में सक्षम होने वाले पृष्ठों को रोकने के लिए डिज़ाइन किया गया है।

मैंने "समान उत्पत्ति नीति जावाएफएक्स" और found the following question की खोज की जो आपकी समस्या का समाधान करेगी।

दोनों ठीक है और अतिरिक्त प्रवेश के साथ पूर्ण आवेदन है:

public class CalendarController extends Application 
{ 
    @Override 
    public void start(Stage primaryStage) throws Exception 
    { 
     WebView browser = new WebView(); 

     WebEngine webEngine = browser.getEngine(); 

     com.sun.javafx.webkit.WebConsoleListener.setDefaultListener(
      (webView, message, lineNumber, sourceId)-> System.out.println("Console: [" + sourceId + ":" + lineNumber + "] " + message) 
     ); 

     webEngine.load("http://calendar.google.com"); 

     StackPane root = new StackPane(); 
     root.getChildren().add(browser); 

     primaryStage.setScene(new Scene(root, 600, 600)); 
     primaryStage.show(); 
    } 

    public static void main(String[] args) 
    { 
     System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); 
     launch(args); 
    } 
} 
संबंधित मुद्दे