Helo
I tryed to upload some data to my webserver. whit curl works fine
curl -s -uedoweb-admin:admin -F"data=@/home/raul/test/t1/6376990.pdf;type=application/pdf" -XPUT api.localhost/resource/frl:6376979/data
and here the trace http://pastebin.com/jJmungAy
here the new methode.
URL myurl;
HttpURLConnection conn;
String port = "9000";
String user = "edoweb-admin";
String password = "admin";
String encoding = Base64.encodeBase64String((user + ":" + password).getBytes());
String boundary = "==" + System.currentTimeMillis() + "===";
String crlf = "\r\n";
String twoHyphens = "--";
String attachmentName = "data";
String attachmentFileName = "6376986.pdf";
DataOutputStream request;
try {
myurl = new URL("http://localhost:9000/resource/frl:6376984/data");
conn = (HttpURLConnection) myurl.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("PUT");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
conn.setRequestProperty("Accept", "*/*");
} catch (Exception e) {
throw new RuntimeException(e);
}
try {
request = new DataOutputStream(conn.getOutputStream());
request.writeBytes(twoHyphens + boundary + crlf);
request.writeBytes("Content-Disposition: form-data; name=\"" + attachmentName + "\";filename=\""
+ attachmentFileName + "\"" + crlf);
request.writeBytes("Content-Type: application/pdf");
request.writeBytes(crlf);
System.out.println(conn.getResponseCode());
} catch (Exception e) {
throw new RuntimeException(e);
}
I found some issues in my code and as well on the webserver. I wrote a new methode and now the server response 400.
can anyone help me?
I found it out by myself.
here the code:
1st mistake was character "=" at the begin of the boundary String. Seems that my Webserver dont like so many equals in the boundary field, so I set just one here:
and removed those from the String boundary
I also get some error message "Packet size out of Limit" in Wireshark and response Code 400 in Java when I try to upload the File but now with this method it works fine. Thank you guys for the support and the suggestions.