1

Esse é o código do meu client:

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");

E esse do meu 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();

Eles não conseguem conversar... alguém pode me dar uma luz? Sou iniciante!

1 Resposta 1

1

Cara, o erro é bem simples:

Tá vendo a linha:

HttpPost post = new HttpPost("localhost");

?

Ela tem que ser alimentada com um pouco mais de informação. Como você tá declarando no server >HTTP< a porta 5030, com o handler "/data" a resolução final fica:

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

Espero ter ajudado :D

1
  • Era isso msm, mt obrigado. Coloquei e funcionou
    – user115863
    11/06/2018 às 20:43

Você deve fazer log-in para responder a esta pergunta.