Sanjiv,

Your problem is that you have to write before doing the connect.
Moving the connect after the out.close() will fix your problem.

Rob Griffin
Quest Software

E-mail: [EMAIL PROTECTED]
Web site: http://www.quest.com

> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
> Sanjiv Arun Sahayam
> Sent: Monday, 7 February 2000 21:48
> To: [EMAIL PROTECTED]
> Subject: small problem with applet servlet communication
>
>
> 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
>

___________________________________________________________________________
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