简体   繁体   中英

Requesting HTTPS and submitting forms in Java

I got the following scenario: On my webserver I have a .do file with HTML code like this:

<form name="login" action="someAction" method="post">
    //some textboxes
</form>
<input type="submit" value="Submit" />

Now I'm trying to make an application, which connects to the webserver - https - fills out the form and get the HTML from the next site (the site, when you're logged in). After that I have to do several JavaScript submits to get the data I want to display it in my desktop application.

I somehow managed to build a connection and get the HTML from the login site, but since I'm new to HttpRequests and stuff like that, I have no idea how to go on.

Help would be appreciated.

Edit: I get the following in my Console:

Sep 24, 2011 2:23:28 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Sep 24, 2011 2:23:30 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Wrapped com.gargoylesoftware.htmlunit.ScriptException: Error: ERROR: No matching script interactive for function () {
    var result = bootstrapDojo();
    result.dojo._dijit = result.dijit;
    result.dojo._dojox = result.dojox;
    return result.dojo;
}

I suggest you to use htmlunit :

HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser.

It has fairly good JavaScript support (which is constantly improving) and is able to work even with quite complex AJAX libraries, simulating either Firefox or Internet Explorer depending on the configuration you want to use.

It is typically used for testing purposes or to retrieve information from web sites.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM