Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4192018

URLConnection.getOutputStream() fails after connect()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.0
    • core-libs
    • merlin
    • x86
    • windows_nt



      Name: jn10789 Date: 11/20/98


      This problem arises with Netscape 4.05, Java Plugin 1.1.1, configured to use JRE 1.2, JDK 1.2 beta 4.
      It worked with older Versions and Internet Explorer's Java VM.

      ------------------------------------------------
      The following JAVA-Code should expose the problem

      ---------------------------------
      try {
      URL url = new URL("http://web-server/cgi-bin/someProg/someFile");
      URLConnection urlConnection = url.openConnection();
      urlConnection.setDoOutput(true);
      urlConnection.connect();
      OutputStream os = urlConnection.getOutputStream();
      }
      catch (Exception ex) {
      ex.printStackTrace();
      }
      ------------------------------------

      This piece of code produces the following exception:

      java.net.ProtocolException: Can't reset method: already connected
       at java.net.HttpURLConnection.setRequestMethod(Compiled Code)
       at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:429)
       at ...
       at java.lang.Thread.run(Thread.java:475)

      ------------------------------------
      When I comment the call connect() out, then no exception is raised, but the connection does not seem to be established. connect() after getOutputStream() has the same effect (besides it doesn't make sense, does it?).

      Documentation on java.net.URLConnection says:
      The following methods are used to access the header fields and the contents >>>after the connection is made<<< to the
      remote object:

           getContent
           getHeaderField
           getInputStream
           getOutputStream
      (Review ID: 37266)
      ======================================================================

            ywangsunw Yingxian Wang (Inactive)
            jdn Jeffrey Nisewanger (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: