Make sure you set the content type for the URLConnection to "application/x-java-serialized-object".  I think the default
ends up being "application/x-www-form-urlencoded", which probably messes-up the server-side parameter parsing --
ie, the server might be trying to parse your serialized object as POSTed params.

I think you would have to do something like:


        URLConnection urlConnection = url.openConnection();
        urlConnection.setDoOutput(true);
        urlConnection.setDoInput(true);
        urlConnection.setRequestProperty( "content-type", "application/x-java-serialized-object" ) ;            // add this


- Fernando

At 03:29 PM 1/13/00 +0100, you wrote:

Our client app tries to send a serialized object to a servlet.

The code looks like this

        // prepareConnection
        URL url = new   
URL("http://myserver/servlet/AddressServlet/insert?addrType=15&parentFolder=17");
        URLConnection urlConnection = url.openConnection();
        urlConnection.setDoOutput(true);
        urlConnection.setDoInput(true);
        urlConnection.setUseCaches(false);
        urlConnection.connect();

        // sending Object
        OutputStream urlOutStream = urlConnection.getOutputStream();
        ObjectOutputStream objOut = new ObjectOutputStream(urlOutStream);
        AdressObject newAddress= getNewAddressObject();
        objOut.writeObject(newAddress); // send request

        // cleanup
        objOut.close();

The client app connect to the servlet but at the servlet side the
parameters from the URL are missing. Only the url
"myserver/servlet/AddressServlet/insert" is transmitted but a
request.getParameter("parentFolder") or getQueryString() returns null.

If we omit sending the serialized object and do the following

        // prepareConnection
        URL url = new           
URL("http://myserver/servlet/AddressServlet/insert?addrType=15&parentFolder=17");
        URLConnection urlConnection = url.openConnection();
        urlConnection.setDoOutput(true);
        urlConnection.setDoInput(true);
        urlConnection.setUseCaches(false);
        urlConnection.connect();
        Object obj=urlConnection.getContent()

        // cleanup
        objOut.close();

everything works fine.

Is it possible to transmit a serliazed object via an URLConnection and
transmit also the UrlQueryString (e.g. the parameters
addrType=15&parentFolder=17) ???

Any help is appreciated.
Thanks in advance, Martin Pfeifer


--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]


=======================================
Fernando Salazar <[EMAIL PROTECTED]>
w -781-392-2514

Reply via email to