Datein Upload via HttpURLConnection?

StefMa

StefMa

Dauergast
450
Hi,

der Ist-Zustand sieht so aus, dass ich eine HTML-Form habe, mit der ich Datein (egal welcher Art) auf einen Server laden kann. Die Form ist ganz simple aufgebaut:
PHP:
<html> 
  <head>
    <title>POST Form</title> 
  </head>

  <body> 
    <form action="https://bucket.server.com/" method="post" enctype="multipart/form-data">
      <input type="hidden" name="key" value="MY_AWESOME_KEY">
      <input type="hidden" name="antoherKey" value="ANOTHER_AWESOME_KEY"> 
      <input type="hidden" name="verischerung" value="MY_AWESOME_VERISCHERUNG">
      <input type="hidden" name="signature" value="MY_AWESOME_SIG">
      <input type="hidden" name="Content-Type" value="">      
      <input type="hidden" name="Content-Length" value="">

      File to upload: 
      <input name="file" type="file"> 
      <br> 
      <input type="submit" value="Upload File"> 
    </form> 
  </body>
</html>

So, das ganze möchte ich nun nachbauen in Java. Am liebsten mit der Klasse HttpURLConnection. Doch anscheinend funktioniert das nicht?! Nur mit irgendwelchen boundaries oder was weiß ich, was man da dran klatschen muss. Gibt es also dazu irgendwelche Alternativen oder schon eine fertige klasse, die von HttpURLConnection erbt und diese funktion erweitert?!

Was ich bisher habe ist die Connection und die Paramter - hoffentlich richtig?! :)
Das sieht dann so aus:
PHP:
HttpURLConnection httpUrlConnection = null;
URL url = new URL("https://bucket.server.com/");
httpUrlConnection = (HttpURLConnection) url.openConnection();
httpUrlConnection.setDoOutput(true);

httpUrlConnection.setRequestMethod("POST");
httpUrlConnection.setRequestProperty("key", "MY_AWESOME_KEY");
httpUrlConnection.setRequestProperty("anotherKey", "MY_AWESOME_OTHER_KEY");
httpUrlConnection.setRequestProperty("versicherung", "MY_AWESOME_VERSICHERUNG");
httpUrlConnection.setRequestProperty("signature", "MY_AWESOME_SIG");
httpUrlConnection.setRequestProperty("Content-Length", "");
httpUrlConnection.setRequestProperty("Content-Type", "");

Nur wie gesagt, an dem File Upload bleibe ich nun hängen... Jmd schon erfahrung damit?

Danke und Gruß

StefMa
 
Zur Lösung sollte man sich mal die lib anschauen http://s.stefma.ws/70f13d

Gesendet von meinem Nexus 10 mit der Android-Hilfe.de App
 
  • Danke
Reaktionen: markus.tullius

Ähnliche Themen

L
Antworten
15
Aufrufe
908
jogimuc
J
M
Antworten
2
Aufrufe
884
manunaut
M
A
  • Artur1990
Antworten
1
Aufrufe
855
swa00
swa00
Zurück
Oben Unten