Bei dem Versuch, sich an https://www.okcupid.com/login
mit der httpunit
-Bibliothek anzumelden, wird der folgende Code erfolgreich ausgeführt.httpunit funktioniert nicht, wenn Klasse JFrame erweitert
Wenn ich jedoch die Klasse mit JFrame
erweitern, damit ich die Benutzeroberfläche erstellen kann, schlägt die Ausführung fehl. Die POST
Anforderung wird ordnungsgemäß abgeschlossen, aber die GET
Anfrage schlägt fehl, wenn HtmlPage page = wc.getPage(url)
ausgeführt wird. Unter dem Code habe ich die Ausgabe für beide Szenarien.
Works, es sei denn Haupt erstreckt JFrame
public class Main /* extends JFrame */ {
static boolean isConnecting = false;
public static void main(String[] args) {
new Main();
}
public Main() {
login();
}
public void login() {
try {
/* POST */
WebClient wc = new WebClient();
URL url = new URL("https://www.okcupid.com/login");
WebRequest requestSettings = new WebRequest(url, HttpMethod.POST);
requestSettings.setRequestBody("username=myLogin&password=myPassword&okc_api=1");
Page redirectPage = wc.getPage(requestSettings);/* unique */
Set<Cookie> cookies = wc.getCookieManager().getCookies();
/*GET */
wc = new WebClient();
for (Cookie cookie : cookies) {
wc.getCookieManager().addCookie(cookie);
}
HtmlPage page = wc.getPage(url);
WebResponse response = page.getWebResponse();
String content = response.getContentAsString();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Ausgabe, wenn Haupt JFrame erweitert
Connected to the target VM, address: '127.0.0.1:52571', transport: 'socket'
Apr 21, 2016 5:31:20 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Apr 21, 2016 5:31:20 PM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError
SEVERE: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector: :x).] sourceName=[https://includes.okccdn.com/flat/js/vendor.min.js?v=7a3cb7237dd753a] line=[24] lineSource=[null] lineOffset=[0]
Exception in thread "main" java.lang.StackOverflowError
at net.sourceforge.htmlunit.corejs.javascript.regexp.NativeRegExp.emitREBytecode(NativeRegExp.java:1311)
at net.sourceforge.htmlunit.corejs.javascript.regexp.NativeRegExp.emitREBytecode(NativeRegExp.java:1281)
.
.
.
.
.
// (this repeats well over a few thousand times before finishing with exit code 1.
at net.sourceforge.htmlunit.corejs.javascript.regexp.NativeRegExp.emitREBytecode(NativeRegExp.java:131
.
.
.
.
.
Disconnected from the target VM, address: '127.0.0.1:52571', transport: 'socket'
Process finished with exit code 1
Ausgabe, wenn Haupt erstreckt sich nicht JFrame
Connected to the target VM, address: '127.0.0.1:52635', transport: 'socket'
Apr 21, 2016 5:38:29 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Apr 21, 2016 5:38:30 PM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError
SEVERE: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector: :x).] sourceName=[https://includes.okccdn.com/flat/js/vendor.min.js?v=7a3cb7237dd753a] line=[24] lineSource=[null] lineOffset=[0]
Apr 21, 2016 5:38:30 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://includes.okccdn.com/lang/en/version/219b51f028bbb87/globals.css' [3:9674] Error in style sheet. (Invalid token "@charset". Was expecting one of: <EOF>, <S>, <IDENT>, "<!--", "-->", ".", ":", "*", "[", <HASH>, <IMPORT_SYM>, <PAGE_SYM>, <MEDIA_SYM>, <FONT_FACE_SYM>, <ATKEYWORD>.)
Apr 21, 2016 5:38:30 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://includes.okccdn.com/lang/en/version/df13e6172aa8212/locals.css?set=home2015,flag_photo' [3:1512] Error in expression. (Invalid token " ". Was expecting one of: <NUMBER>, "inherit", <IDENT>, <STRING>, <HASH>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <URI>, <FUNCTION>.)
Apr 21, 2016 5:38:30 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://includes.okccdn.com/lang/en/version/df13e6172aa8212/locals.css?set=home2015,flag_photo' [3:1543] Error in expression. (Invalid token " ". Was expecting one of: <NUMBER>, "inherit", <IDENT>, <STRING>, <HASH>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <URI>, <FUNCTION>.)
Apr 21, 2016 5:38:30 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://includes.okccdn.com/lang/en/version/df13e6172aa8212/locals.css?set=home2015,flag_photo' [3:1566] Error in expression. (Invalid token " ". Was expecting one of: <NUMBER>, "inherit", <IDENT>, <STRING>, <HASH>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <URI>, <FUNCTION>.)
Apr 21, 2016 5:38:30 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://includes.okccdn.com/lang/en/version/df13e6172aa8212/locals.css?set=home2015,flag_photo' [3:3949] Error in expression. (Invalid token " ". Was expecting one of: <NUMBER>, "inherit", <IDENT>, <STRING>, <HASH>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <URI>, <FUNCTION>.)
Apr 21, 2016 5:38:30 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://includes.okccdn.com/lang/en/version/df13e6172aa8212/locals.css?set=home2015,flag_photo' [3:3982] Error in expression. (Invalid token " ". Was expecting one of: <NUMBER>, "inherit", <IDENT>, <STRING>, <HASH>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <URI>, <FUNCTION>.)
Apr 21, 2016 5:38:30 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://includes.okccdn.com/lang/en/version/df13e6172aa8212/locals.css?set=home2015,flag_photo' [3:4007] Error in expression. (Invalid token " ". Was expecting one of: <NUMBER>, "inherit", <IDENT>, <STRING>, <HASH>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <URI>, <FUNCTION>.)
.
.
.
.
.
.
.
.
.
and so on, and so forth
.
.
.
.
.
.
.
<!DOCTYPE html>
DESIRED HTML RESPONSE STRING
</html>
.
.
// After connecting successfully, the following continues to output every 30 seconds
Apr 21, 2016 5:39:00 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'https://1-instant.okcupid.com/instantevents?random=0.437989956299249', but got 'text/html'.
Apr 21, 2016 5:39:29 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'https://2-instant.okcupid.com/instantevents?random=0.4299430644437371&server_seqid=0&server_gmt=1461274740', but got 'text/html'.