WebClient:
´´´
public class WebClient {
public String post(String json){
try {
//Determina a conecxao com o servidor
URL url = new URL("https://wwww.caelum.com.br/mobile");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//Informando ao servidor o que esta sendo enviado e o que deve ser retornado
connection.setRequestProperty("Content-type","application/json");
connection.setRequestProperty("Accept","application/json");
connection.setDoOutput(true);
PrintStream output = new PrintStream(connection.getOutputStream());
output.println(json);
connection.connect();
//Recebe a leitura envida pelo servidor
Scanner scanner = new Scanner(connection.getInputStream());
String resposta = scanner.next();
return resposta;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
´´´