title: HttpRequest from app engine endpoint. Connection reset
body: <p>I am trying to send an HTTP request from an APP Engine endpoint, from experiments on Postman I know the result is quite big, and the the request usually takes about a minute.</p>
  
  <p>here is my Code:</p>
  
  <pre><code>void testRequest() {
      String test = getConnectionString();
      URL url = new URL(YARDI_URL);
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.setDoOutput(true);
      connection.setInstanceFollowRedirects(false);
      connection.setRequestMethod("POST");
      connection.setRequestProperty("Content-Type", "text/xml");
      connection.setConnectTimeout(1000000);
      OutputStream os = connection.getOutputStream();
      PrintWriter p = new PrintWriter(os);
      p.print(test);
      p.close();
  
      YardiResponse response = new 
      YardiResponse(connection.getInputStream().toString());
  
      System.out.println(response.getResponse());
      connection.disconnect();
  }
  </code></pre>
  
  <p>I am getting two errors, </p>
  
  <p>the first is: <code>java.net.ProtocolException: Cannot write output after reading input.
  </code></p>
  
  <p>and after a long time I am getting a <code>java.net.SocketException: Connection reset</code> message.</p>
  
  <p>Obviously I am mishandling the steams, and the way I send them.</p>