Olá,
Estou cadastrando o aluno pelo celular, não estou usando o emulador, está gerando o erro mais abaixo.
Não achei nenhum tópico relacionado.
Estou procurando na net, mas pode ser alguma configuração no cel. para acessar o ip do note. Caso alguém tenha passado pelo mesmo problema, poste aqui.
Obrigado!
Erro:
W/System.err: java.net.ConnectException: failed to connect to /192.168.85.1 (port 8080): connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.IoBridge.connect(IoBridge.java:124)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:452)
at java.net.Socket.connect(Socket.java:884)
at com.android.okhttp.internal.Platform.connectSocket(Platform.java:117)
at com.android.okhttp.internal.http.SocketConnector.connectRawSocket(SocketConnector.java:434)
at com.android.okhttp.internal.http.SocketConnector.connectCleartext(SocketConnector.java:105)
at com.android.okhttp.Connection.connect(Connection.java:1333)
at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:1412)
at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:131)
at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:485)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:466)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:372)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:476)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:118)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:249)
at br.com.alura.agenda.WebClient.realizaConexao(WebClient.java:37)
at br.com.alura.agenda.WebClient.insere(WebClient.java:21)
at br.com.alura.agenda.tasks.InsereAlunoTask.doInBackground(InsereAlunoTask.java:22)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.Posix.connect(Native Method)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)
at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
at libcore.io.IoBridge.connect(IoBridge.java:122)
... 24 more
WebClient:
public class WebClient {
public String post(String json){
String endereco = "https://www.caelum.com.br/mobile";
return realizaConexao(json, endereco);
}
public void insere(String json) {
String endereco = "http://192.168.85.1:8080/api/aluno";
realizaConexao(json, endereco);
}
@Nullable
private String realizaConexao(String json, String endereco) {
try {
URL url = new URL(endereco);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//tipo de dado que está enviando
connection.setRequestProperty("Content-type","application/json");
//tipo de dado que aceita como resposta
connection.setRequestProperty("Accept","application/json");
connection.setDoOutput(true);//quero fazer um post no corpo da requisicao
//escrever no corpo da requisição o q enviar
PrintStream output = new PrintStream(connection.getOutputStream());
output.println(json);
//enviar e pegar a resposta
//estabelece a conexao
connection.connect();
//pegar a resposta
Scanner scanner = new Scanner(connection.getInputStream());
//ler a resposta do servidor
String resposta = scanner.next();
return resposta;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}