Webformular ausfüllen

U

Umbralupus

Moin,
Ich möchte eine Java-Anwendung die lokal läuft und bei einer vorgebenen Seite ein Formular ausfüllt und mir das Ergebnis dann zurück gibt. Das Programm habe ich schon zusammengeschrieben und es funktioniert auch bei ein paar Seiten die mit post und JavaScript Formularen arbeiten.

Aber da wo es gehen soll, gehts natürlich nicht:
"http://ted.publications.eu.int/official/Exec?DataFlow=ShowPage.dfl&Template=TED/extended_search#"

Ich habe dort mit Mozilla und den Http Live Headers bereits ausgelesen welcher befehl per post übergeben werden sollten.

Es scheint aber so, als wenn es da nicht ankommt.
Da dies kein Problem meiner Anwendung sondern meines Verständnis von JavaSkript und Formularen im Web ist hoffe ich hier kann mir einer helfen.





Hier der Code:


Code: import java.net.*;
import java.io.*;

public class Test {

public static void main(String[] args) {
try
{
// Url der Startseite
String resultURL ="http://ted.publications.eu.int/official/Exec?DataFlow=ShowPage.dfl&Template=TED/extended_search#";


// Aufbau einer Verbindung zur Webseite
URL postURL = new URL(resultURL);
System.out.println(">>> Verbdinung wir aufgebaut .....");
HttpURLConnection con = (HttpURLConnection) postURL.openConnection();

// Eigenschaften der Verbindung
con.setUseCaches(false); // nutze keinen cache
con.setDoOutput(true); // benutzen für output
con.setDoInput(true); // benutzen für Input
con.setRequestMethod("POST"); // benutze Post um Daten zu übertragen


PrintWriter out = new PrintWriter(con.getOutputStream());

// Aufbau des Strings für die Übergabe der Werte, hier von den HTTP Live Headers genommen
String U="UTF-8";
String postStr;
postStr =" /official/SettingSessionVariables Name=listretrieval%40displayCriteria%40fulltext_textfield%40OJ_textfield%40country_textfield%40place_textfield%40contract_textfield%40procedure_textfield%40document_textfield%40regulation_textfield%40CPV_textfield%40NUTS_textfield%40publication_textfield%40docnumber_textfield%40datedoc_textfield%40deadline_textfield%40type_author_textfield%40name_author_textfield%40heading_textfield%40fulltext_textfield_hid%40OJ_textfield_hid%40country_textfield_hid%40place_textfield_hid%40contract_textfield_hid%40procedure_textfield_hid%40document_textfield_hid%40regulation_textfield_hid%40CPV_textfield_hid%40NUTS_textfield_hid%40publication_textfield_hid%40docnumber_textfield_hid%40datedoc_textfield_hid%40deadline_textfield_hid%40type_author_textfield_hid%40name_author_textfield_hid%40heading_textfield_hid%40docLang%40maxRow%40SelRetrieval%40FTIndex%40SearchFrom%40ExpertQry%40op1%40op2%40Query&Value=code%2COJ%2CND%2CTI%40No%40null%40null%40DE%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40%28+CY%3ADE%29%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40null%40DE%40100%40OJ%2CND%2CTI%40TEDINDEX%40extended%40null%40AND%40AND%40cs_type%3Adb++AND+%28%28+CY%3ADE%29%29&Redirect=Exec%3FDataFlow%3Dlist_results.dfl%26TableName%3DTED_DE%26Template%3DTED%2Fresult_list.xsl";


// Übertrage Post
System.out.println(">>> Poste: "+postStr);
out.println(postStr); // sende an Server
out.close(); // übertrage den Outputstream


//Get the results page from the server
String inputLine=""; //Stores the line of text returned by the server
String resultsPage=""; // Stores the complete HTML results page

System.out.println(">>> Waiting for response...\n\n");
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));

while ((inputLine = in.readLine()) != null)
resultsPage+=inputLine;
in.close();

// Dump the results page onto the console
// resultsPage contains the entire HTML result page
// You can write it to a file or display on the screen
System.out.println(resultsPage);

FileOutputStream outf; // declare a file output object
PrintStream p; // declare a print stream object

try
{
// Create a new file output stream
// connected to "myfile.txt"
outf = new FileOutputStream("myfile.html");

// Connect print stream to the output stream
p = new PrintStream( outf );

p.println (resultsPage);

p.close();
}
catch (Exception e)
{
System.err.println ("Error writing to file");
}


}




catch(Exception e){
// catch any exceptions
System.out.println(e);
}//end catch
} // end main
} // end class
 
Zurück