Kevin,
Yes you are right. You need to call setDoOutput(true).
However calling getOutputStream does force a POST.
See sun.net.www.protocol.http.HttpURLConnection for details.
Regards,
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 Kevin
> Jones
> Sent: Friday, 19 January 2001 9:46
> To: [EMAIL PROTECTED]
> Subject: Re: urgent...
>
>
> Not on my system -
>
> I've just tried this and I get an exception.
>
> If I call setDoOutput(true);
>
> then write I get POST.
>
> If I don't call setDoOutput(true) then it throws an exception.
>
> Here's the code
>
> java.net.URL url = new java.net.URL(urlString);
> java.net.HttpURLConnection con =
> (java.net.HttpURLConnection)url.openConnection();
> // con.setDoOutput(true);
> // con.setRequestMethod("POST");
>
> java.io.OutputStreamWriter writer = new
> java.io.OutputStreamWriter(con.getOutputStream());
>
> and here's the exception
>
> java.net.ProtocolException: cannot write to a URLConnection if
> doOutput=false - call setDoOutput(true)
> at
> sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknow
> n Source)
> at Client.main(Client.java:22)
>
> This is on W2K with jdk1.3
>
> If i remove the comment on setDoOutput(true) then it works fine.
>
> Try it,
>
>
> Kevin Jones
> DevelopMentor
> www.develop.com
>
> > -----Original Message-----
> > From: A mailing list for discussion about Sun Microsystem's Java Servlet
> > API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Rob
> > Griffin
> > Sent: 18 January 2001 22:18
> > To: [EMAIL PROTECTED]
> > Subject: Re: urgent...
> >
> >
> > > -----Original Message-----
> > > From: A mailing list for discussion about Sun Microsystem's
> Java Servlet
> > > API Technology. [mailto:[EMAIL PROTECTED]]On
> Behalf Of Kevin
> > > Jones
> > > Sent: Friday, 19 January 2001 7:50
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: urgent...
> > >
> > >
> > > But only for POST or PUT, whcich this code isn't using
> >
> > Yes it is. Writing to the output stream of a URLConnection forces
> > it to do a POST.
> >
> > >
> > >
> > > con.setRequestProperty("Content-Type","java-internal"+objs.getClas
> > > s().getNam
> > > e());
> > > ObjectOutputStream out = new
> > ObjectOutputStream(con.getOutputStream());
> > > out.writeObject(objs);
> > >
> > > you should call con.setDoOutput(true);
> > > or con.setRequestMethod("POST"); // JDK1.3 and above I think
> > >
> > > In fact the code shouldn't even execute.
> > >
> > > Thinking about it I assume there should be a call to
> > > setDoOutput(true) here
> > > somewhere?
> >
> > ------------- from another post
> >
> > >> IE returns FileNotFoundException when it can't connect
> > >
> > >It's not IE that does this. URLConnection converts EVERY error
> > code into a
> > >FileNotFoundException
> >
> > Netscape throws an IOException in this case.
> >
> > >
> > > Kevin Jones
> > > DevelopMentor
> > > www.develop.com
> > >
> >
> > [snip]
> >
> > Rob Griffin
> > Quest Software
> >
> > E-mail: [EMAIL PROTECTED]
> > Web site: http://www.quest.com
> >
> > __________________________________________________________________
> > _________
> > 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
>
___________________________________________________________________________
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