简体   繁体   English

使用Java请求HTTPS和提交表单

[英]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: 我遇到以下情况:在我的Web服务器上,我有一个带有HTML代码的.do文件,如下所示:

<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). 现在,我正在尝试制作一个应用程序,该应用程序连接到Web服务器-https-填写表单,并从下一个站点(登录时为该站点)获取HTML。 After that I have to do several JavaScript submits to get the data I want to display it in my desktop application. 之后,我必须执行几个JavaScript提交来获取要在桌面应用程序中显示的数据。

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. 我以某种方式设法建立了一个连接并从登录站点获取HTML,但是由于我是HttpRequests之类的新手,所以我不知道如何继续。

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

HtmlUnit is a "GUI-Less browser for Java programs". HtmlUnit是“用于Java程序的无GUI浏览器”。 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. 它为HTML文档建模,并提供一个API,使您可以调用页面,填写表单,单击链接等,就像在“常规”浏览器中一样。

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. 它具有相当好的JavaScript支持(正在不断改进),并且即使在非常复杂的AJAX库中也可以工作,根据您要使用的配置模拟Firefox或Internet Explorer。

It is typically used for testing purposes or to retrieve information from web sites. 它通常用于测试目的或从网站检索信息。

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

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