My client can not find my HttpServer?

1

This is my client's code:

public static void main(String[] args) throws IOException, InterruptedException {
            SendData sender = new SendData();
            String JsonDeDados;
            String infos = "informacoes";

            HttpClient client = HttpClientBuilder.create().build();
            CloseableHttpClient clientclose = HttpClients.createDefault();
            HttpPost post = new HttpPost("localhost");

And this one from my server:

public static void main(String[] args) throws IOException {
        HttpServer server = HttpServer.create(new InetSocketAddress(5030), 0);
        System.out.println("Executando");
        server.createContext("/data", new dataHandler());
        server.setExecutor(null);
        server.start();

They can not talk ... can someone give me a light? I'm a beginner!

    
asked by anonymous 11.06.2018 / 22:37

1 answer

1

Man, the error is quite simple:

Seeing the line:

HttpPost post = new HttpPost("localhost");

?

It has to be fed with a bit more information. As you are declaring on the server > HTTP < port 5030, with the handler "/ data" the final resolution is:

HttpPost post = new HttpPost("http://localhost:5030/data");

I hope I have helped: D

    
11.06.2018 / 22:40