ERLEDIGT
JA
JA
ANTWORTEN
1
1
ZUGRIFFE
812
812
EMPFEHLEN
-
Hallo zusammen,
kann mir bitte jemand helfen den Fehler zu finden?
Ich möchte mit diesem Code (danke an experts-exchange.com) ein File versenden.
Leider kommt es aber nicht an obwohl die Connection aufgebaut ist. Wenn ichs mit einem html-Form über den Browser mache gehts.
Mit Bestem Dank
xrax
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; public class TestHttp { public static void main(String[] args) throws Exception { String url = "http://www.sport.de:80/api/external_writer.php?Token=2729cd0867d4bf60a1ac6da97375df"; String docPath = "D:\\SSW\\workspace\\Modules\\Test_out_result.xml"; // Document HttpURLConnection httpcon = (HttpURLConnection) ((new URL(url).openConnection())); httpcon.setDoOutput(true); httpcon.setUseCaches(false); httpcon.setRequestProperty("Content-Type", "multipart/form-data"); httpcon.connect(); System.out.println("Posting " +docPath +"..."); File file = new File(docPath); FileInputStream is = new FileInputStream(file); OutputStream os = httpcon.getOutputStream(); // POST // Read bytes until EOF to write byte[] buffer = new byte[4096]; int bytes_read; // How many bytes in buffer while((bytes_read = is.read(buffer)) != -1) { os.write(buffer, 0, bytes_read); } os.close(); is.close(); try { InputStream in = httpcon.getInputStream(); int x; while ( (x = in.read()) != -1) { System.out.write(x); } in.close(); BufferedReader r = new BufferedReader(new InputStreamReader(in)); StringBuffer buf = new StringBuffer(); String line; while ((line = r.readLine())!=null) { buf.append(line); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Done..."); } }HTML-Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <meta name="author" content="foo"> <meta name="editor" content="html-editor phase 5"> </head> <body text="#000000" bgcolor="#FFFFFF" link="#FF0000" alink="#FF0000" vlink="#FF0000"> <form action="http://www.sport.de:80/api/external_writer.php?Token=2729cd0867d4bf60a1ac6da97375df" enctype="multipart/form-data" method="post"> <p> Please specify a file:<br> <input type="file" name="datafile.xml" size="40"> </p> <div> <input type="submit" value="Send"> </div> </form> </body> </html>
-
28.05.10 11:04 #2
Hallo,
die html-Form verwendet POST. Hast du mal getestet, ob das was ausmacht?
Code java:1
httpcon.setRequestMethod("POST");
Denken gefärdet die Gewohnheit
Ähnliche Themen
-
File Button teilweise verstecken, geht unter IE nicht
Von one6666 im Forum CSSAntworten: 2Letzter Beitrag: 16.04.10, 12:56 -
Formular auf website, wie geht die send funktion?
Von hauke1981 im Forum HTML & XHTMLAntworten: 9Letzter Beitrag: 27.03.08, 15:48 -
Illustrator File importieren geht nicht!!
Von Xanderl im Forum Cinema 4DAntworten: 4Letzter Beitrag: 06.02.06, 14:10 -
file edit per php, geht irgendwie nicht
Von monzon im Forum PHPAntworten: 6Letzter Beitrag: 02.02.06, 22:40 -
include file geht nicht
Von PhoenixDH im Forum ASPAntworten: 2Letzter Beitrag: 23.08.05, 15:18





Zitieren
Login





