Uploading from Java applet using HTTP Post method

Posted on 1997-05-09
Last Modified: 2008-03-06

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/\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?
Question by:Zero050997
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

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


Expert Comment

ID: 1220301
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.

Author Comment

ID: 1220302
The problem has been solved. The header had to be sent like this:

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


Expert Comment

ID: 1220303

Now contact the customer support forum of experts exchange and cancel your question so that you can get your points back.

Accepted Solution

keegi earned 50 total points
ID: 1220304
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());


Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
going to wrong jsp page 2 71
ejb entity bean example 2 59
jmss example java 2 48
Why is enum singleton a better approach than static factory 3 67
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question