Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   [Java] org.apache.http - Dateiupload (https://www.delphipraxis.net/151594-%5Bjava%5D-org-apache-http-dateiupload.html)

FriFra 24. Mai 2010 19:52


[Java] org.apache.http - Dateiupload
 
Hallo zusammen,

ich versuche gerade erfolglos eine Datei hoch zu laden...

HTML-Form:
XML-Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Rufnummern (Kurzwahl- und Telefonbuch)</title>
</head>

<body class="d3">
<form name="import_form" method="post" action="http://192.168.123.8/telefonbuch_kurzwahl?im_file=kurzwahlen&actionNo=12" accept-charset="ISO-8859-1" enctype="multipart/form-data">
<input type="file" name="im_file" size="70">
<input type=submit>
</form>
</body>
</html>
Mein Versuch in Java sieht bisher so aus:
Code:
 httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
 
                HttpPost httppost = new HttpPost(sURL+"/telefonbuch_kurzwahl?im_file=kurzwahlen&actionNo=12");
                File file = new File("d:/rufnummern.txt");
 
                MultipartEntity mpEntity = new MultipartEntity();
                ContentBody cbFile = new FileBody(file, "text/plain");
                mpEntity.addPart("im_file", cbFile);
 
                httppost.setEntity(mpEntity);
                System.out.println("executing request " + httppost.getRequestLine());
                response = httpclient.execute(httppost);
                HttpEntity resEntity = response.getEntity();
 
                System.out.println(response.getStatusLine());
                if (resEntity != null) {
                    System.out.println(EntityUtils.toString(resEntity));
                }
                if (resEntity != null) {
                    resEntity.consumeContent();
                }
Ich bekomme zwar den Status 200 OK, aber die Datei kommt nicht an. Irgendwie kann ich kein funktionierendes Code-Beispiel finden :roll:

[edit=Luckie] Mfg, Luckie[/edit]
[edit=Luckie] Mfg, Luckie[/edit]

Zacherl 24. Mai 2010 20:07

Re: [Java] org.apache.http - Dateiupload
 
OT: Wieso wird der HTML Code geparst? Das ist ne ziemlich große Sicherheitslücke ^^

Luckie 24. Mai 2010 20:09

Re: [Java] org.apache.http - Dateiupload
 
Danke für den Hinweis. Habe mal korrigiert.


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:23 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz