Can’t my client find my Httpserver?

Asked

Viewed 26 times

1

That’s my client 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 the one on 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’t talk... can someone give me a light? I’m a beginner!

1 answer

1


Man, the mistake is pretty simple:

You see the line:

HttpPost post = new HttpPost("localhost");

?

She needs to be fed a little more information. As you are declaring on the server >HTTP< the port 5030, with Handler "/data" the final resolution is:

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

I hope I helped :D

  • That was me, thank you. I put and it worked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.