Hi all,

I am having some trouble sending binary data to a servlet from an
applet/application.

The following exception is thrown when I try to send the data :


java.net.ProtocolException: Can't reset method: already connected
        at
java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:10
6)
        at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLCo
nnection.java:406)
        at Sender.main(Sender.java:28)



The code I used is shown below:



import java.net.*;
import java.io.*;

public class Sender
{

  public static void main(String args[])
  {
    try
    {

      URL url = new URL("http","sanjiv",80,"/servlet/SvltReceiver");
      URLConnection con = url.openConnection();
      con.setDoOutput(true);
      con.setDoInput(false);
      String str = "hello";

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      DataOutputStream dos = new DataOutputStream(baos);
      dos.writeUTF(str);
      dos.close();

      byte buffer[] = baos.toByteArray();
      con.setRequestProperty("Content-type",";application/octet-stream");
      con.setRequestProperty("Content-length",""+buffer.length);
      con.connect();

      DataOutputStream out = new DataOutputStream(con.getOutputStream());
// assertion occurs here
      out.write(buffer);
      out.close();
    }
    catch(Exception e)
    {
      e.printStackTrace(System.out);
    }
 }

}



thanks,

Sanjiv

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to