Hi, ich möchte von einen Applet, wo ich Dateien(Bilder) auswähle, weiterschicken an eine Php Seite. Aber ich mache irgend ein Fehler, ich empfange nicht mal einen String den ich extra mitschick. Hier der Java code vielleicht kann mir einer helfen.
PHP:
private void btnabschickenActionPerformed(java.awt.event.ActionEvent evt) {
URL url=null;
try{
url=new URL("http://localhost/testphp.php");
}
catch(MalformedURLException me){}
try{
try{
String hostname = "localhost";
int port = 80;
InetAddress addr = InetAddress.getByName(hostname);
Socket socket = new Socket(addr, port);
// Send header
String path = "/testphp.php";
File theFile = new File("C:\\Dokumente und Einstellungen\\Eigene Dateien\\buecherseiten.jpg");
System.out.println ("size: " + (int) theFile.length());
DataInputStream fis = new DataInputStream(new BufferedInputStream(new
FileInputStream(theFile)));
byte[] theData = new byte[(int) theFile.length( )];
fis.readFully(theData);
fis.close();
DataOutputStream raw = new
DataOutputStream(socket.getOutputStream());
Writer wr = new OutputStreamWriter(raw);
String command =
"POST "+path+" HTTP/1.0\r\n"
+ "Content-type: multipart/form-data, boundary=mango\r\n"
+ "Content-length: " + ((int) theFile.length()) + "\r\n"
+ "\r\n"
+ "--mango\r\n"
+ "content-disposition: name=\"MAX_FILE_SIZE\"\r\n"
+ "\r\n"
+ "\r\n--mango\r\n"
+ "content-disposition: attachment; name=\"datafile\""
+ "filename=\"test.jpg\"\r\n"
+ "Content-Type: image/jpeg\r\n"
+ "Content-Transfer-Encoding: binary\r\n"
+ "\r\n";
wr.write(command);
wr.flush();
raw.write(theData);
raw.flush( );
wr.write("\r\n--mango--\r\n");
wr.flush( );
BufferedReader rd = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
wr.close();
raw.close();