title: com.sun.net.httpserver doesn't work with org.apache.http.client
body: <p>I make two requests from one client to the server and client hangs on second execute of method httpclient.execute(httpPost); if I create new client for each request everything is OK. If I make POST to google(for example) everything is OK. What's the problem?</p>
  
  <p>Server:</p>
  
  <pre><code>public static void main(String[] args) throws IOException {
      HttpServer server = HttpServer.create(new InetSocketAddress("localhost", 8080),2);
      server.setExecutor(Executors.newFixedThreadPool(5));
      HttpContext context = server.createContext("/", new GlobalHandler());
      context.getFilters().add(new GlobalFilter());
      server.createContext("/setup.exe", new GetFileHandler());
      server.start();
  }
  
  
  private static class GlobalHandler implements HttpHandler {
      @Override
      public void handle(HttpExchange t) throws IOException {
          Headers headers = t.getRequestHeaders();
  
          System.out.println(headers.entrySet());
  
          System.out.println(t.getHttpContext());
          System.out.println(t.getRequestURI());
          System.out.println(t.getProtocol());
          System.out.println(t.getRequestMethod());
          String resp = "Hello";
          if (Objects.equals(t.getRequestMethod(), "POST")) {
              System.out.println("POST");
              Map params = (Map) t.getAttribute("parameters");
              resp = params.toString();
              System.out.println(params);
          }
  
          byte[] bytesToWrite = resp.getBytes("UTF-8");
          t.sendResponseHeaders(200, bytesToWrite.length);
          OutputStream os = t.getResponseBody();
          os.write(bytesToWrite);
      }
  }
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>    RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(1 * 1000).build();
      httpclient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
  
      for(int i= 0;i&lt;2;i++) {
  
          HttpPost httpPost = new HttpPost("http://google.com");
          httpPost.addHeader("Connection","keep-alive");
          List&lt;NameValuePair&gt; nvps = new ArrayList&lt;NameValuePair&gt;();
          nvps.add(new BasicNameValuePair("username", "вг"));
          nvps.add(new BasicNameValuePair("password", "аб"));
          httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
          CloseableHttpResponse response2 = httpclient.execute(httpPost);
  
          try {
              System.out.println(response2.getStatusLine());
              HttpEntity entity2 = response2.getEntity();
              if(entity2.getContentLength() &gt;0) {
                  byte[] content = new byte[(int) entity2.getContentLength()];
                  entity2.getContent().read(content);
                  System.out.println(new String(content, "UTF-8"));
              }
              EntityUtils.consume(entity2);
          } finally {
              response2.close();
  
          }
      }
      httpclient.close();
  </code></pre>