A
autogoor
I am using the following code to upload a large binary data to a http
server.
URL u = new URL(urlString);
URLConnection c = u.openConnection();
c.setDoOutput(true);
c.setDoInput(true);
c.setUseCaches(false);
// set some request headers
c.setRequestProperty(
"Connection",
"Keep-Alive");
// get codebase of the this (the applet) to use for referer
c.setRequestProperty(
"HTTP_REFERER",
codebase);
c.setRequestProperty(
"Content-Type",
"multipart/form-data; boundary=" + boundary);
DataOutputStream dstream = new
DataOutputStream(c.getOutputStream());
for (int i = 0; i < 1000; i++){
byte[] data = new byte[1000];
data = ....
dstream.write(dataq,0,1000);
}
dstream.writeBytes("\r\n--" + boundary + "--\r\n");
dstream.flush();
dstream.close();
I found that the data was never sent. If I put the following line after
the code above, however, the data got sent. Why?
c.getInputStream();
server.
URL u = new URL(urlString);
URLConnection c = u.openConnection();
c.setDoOutput(true);
c.setDoInput(true);
c.setUseCaches(false);
// set some request headers
c.setRequestProperty(
"Connection",
"Keep-Alive");
// get codebase of the this (the applet) to use for referer
c.setRequestProperty(
"HTTP_REFERER",
codebase);
c.setRequestProperty(
"Content-Type",
"multipart/form-data; boundary=" + boundary);
DataOutputStream dstream = new
DataOutputStream(c.getOutputStream());
for (int i = 0; i < 1000; i++){
byte[] data = new byte[1000];
data = ....
dstream.write(dataq,0,1000);
}
dstream.writeBytes("\r\n--" + boundary + "--\r\n");
dstream.flush();
dstream.close();
I found that the data was never sent. If I put the following line after
the code above, however, the data got sent. Why?
c.getInputStream();