title: Can't reset method: already connected
body: <p>I have seen this error will throw if called getInputStream before, but I have not in my code and I have checked the connected property is false, but still show this error. the code is as follow:</p>
  
  <pre><code>private void testConnect() throws Exception{
      HttpURLConnection con = null;
      OutputStream httpsend = null;
      String url = "https://xxxxx/goldapi/rs/checkPaymentService";
  
      TrustManager[] trustall = new TrustManager[] { 
          new X509TrustManager() {
              public java.security.cert.X509Certificate[] getAcceptedIssuers() { 
                  return new X509Certificate[0];
              }
              public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType) {}
  
              public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {}
          } 
      }; 
      SSLContext sc = SSLContext.getInstance("SSL");
      sc.init(null, trustall, new SecureRandom()); 
      HostnameVerifier allHostsValid = new HostnameVerifier() {
           @Override
           public boolean verify(String hostname, SSLSession session) {
               System.out.println("URL Host: " + hostname + " vs. " + session.getPeerHost());
               return true;
           }
      };
      HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
  
      HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
      con = (HttpsURLConnection)(new URL(url).openConnection());
      con.setConnectTimeout(100000);
  
      // Set HTTP parameters for SOAP call
      //con.disconnect(); // test
      con.setAllowUserInteraction(true);
      con.setRequestMethod("POST");
  
      con.setDoOutput(true);
      con.setDoInput(true);
      con.setUseCaches(false);
      byte[] b = "test".getBytes();
      con.setRequestProperty( "Content-Length", String.valueOf( b.length));
      con.setRequestProperty("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    //Send request to server
      httpsend = con.getOutputStream();
      httpsend.write(b);
      httpsend.flush();
      try{
          httpsend.close();
      }catch(Exception e){
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>it will throws Exception</p>
  
  <blockquote>
    <p>Exception in thread "main" java.net.ProtocolException: Can't reset method:<br>
      at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:320)<br>
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestMethod  (HttpsURLConnectionImpl.java:354)<br>
      at Test.PSGConnectTest.testConnect(PSGConnectTest.java:62)<br>
      at Test.PSGConnectTest.main(PSGConnectTest.java:24)</p>
  </blockquote>
  
  <p>already connectedI found that I need to explicit write </p>
  
  <pre><code>con.disconnect();
  </code></pre>
  
  <p>to prevent this error, but then another strange exception throw when running</p>
  
  <pre><code>httpsend = con.getOutputStream();
  </code></pre>
  
  <p>this statement will throws exception as follow</p>
  
  <blockquote>
    <p>java.net.ProtocolException: Cannot write output after reading input.</p>
  </blockquote>
  
  <p>but I have not reading any input (no getInputStream before), so what is the problem?</p>
  
  <p>Update:
  I found this error only occur when I use debug mode in eclipse, no this error if run in eclipse run mode.</p>