Uploading from Java applet using HTTP Post method

I've run into some problems uploading some ascii and binary data from a
Java applet to a cgi-script running on Apache 1.0.5 HTTP server under
FreeBSD using the POST method.

Apparently the server just can't get the content length out of the stream
I send. On a MS IIS 2 server it worked to some extent, though when the
length crossed some certain limit, the IIS recieved just the first 900
bytes (I suspect thats some kind of default for cases it can't read
content length)...

Just in case i paste here the piece of code i use to initiate data

      Socket s = new Socket("hostname", 80);

      DataOutputStream out = new DataOutputStream(s.getOutputStream());
      out.writeBytes("POST /cgi-bin/script.pl\n");
      out.writeBytes("Content-length: " + length + "\n");
      out.writeBytes("Content-type: application/octet-stream\n\n");

Does anyone have any sample code or reference URL's to check?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you using a proxy server? Some proxies limit the amount of data allowed in a POST operation.

Two other alternatives I can think of:

Try sending a \r\n pair rather than just a \n.

Try using the URLConnection class to do the post. See:


for an example on how to do this.
Zero050997Author Commented:
The problem has been solved. The header had to be sent like this:

out.writeBytes("POST /cgi-bin/skript.pl HTTP/1.0\r\n");


Now contact the customer support forum of experts exchange and cancel your question so that you can get your points back.
Anyway, I'm greedy about points ;-) and I propose an more elegant answer (imho), using URLs instead of Socket

URL gather = new URL("http://myhost/cgi-bin/gather.cgi");
URLConnection c = gather.openConnection();

Now you can get and write to the output stream:

DataOutputStream os = new DataOutputStream(c.getOutputStream());


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.