title: JAVA : how to send and receive Json String using HTTP from Client To Server and vice versa
body: <p>client programming over sockets in java but im new in HTTP client-server apps . </p>
  
  <p>however im trying to write client-server application which the client should be able to send messeges to server and hear the result back and they should be able to send and receive files .
  what i've done so far is creating a Server using <code>com.sun.net.httpserver</code> ( which i dont know if is suitable or not , it was the only thing i could find a good tutorial for it ):</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
          HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
          server.createContext("/test", new MyHandler());
          server.setExecutor(null);
          server.start();
  }
  
  static class MyHandler implements HttpHandler {
      @Override
      public void handle(HttpExchange t) throws IOException {
          System.out.println(t.getHttpContext());
          String response = "This is the response";
          t.sendResponseHeaders(200, response.length());
          OutputStream os = t.getResponseBody();
          os.write(response.getBytes());
          os.close();
      }
  }
  </code></pre>
  
  <p>and i could successfully create a connection to this server using <code>java.net.URL</code> and <code>java.net.HttpURLConnection</code> .
  but i dont know how should i send and recieve strings and files on both sides ! and i couldn't even find a good complete tutorial for that . </p>
  
  <p>so now i wish someone to give me a simple example on how to do that ?
  or if there is any good and easy to learn library i can use for this ? ( of course i need some tutorials first )</p>
  
  <p>thanks in advance</p>