I am working with a Web Service made in ASP.NET, the problem is that I can not run the url localhost from my android device, I used the IP address of my computer in this way in the mobile browser: link or link but do not there's an answer, I also tried disabling the firewall.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info_user);
mensaje= (TextView)findViewById(R.id.textView8);
info = (TextView)findViewById(R.id.textView9);
btnBuscar = (Button)findViewById(R.id.btnBuscar);
btnBuscar.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v)
{
new ObtenerDatosUsuario().execute("localhost:8433/odata/Usuarios");
}
});
}
private class ObtenerDatosUsuario extends AsyncTask<String, String, String>
{
HttpURLConnection connection = null;
BufferedReader reader = null;
@Override
protected String doInBackground(String... params)
{
try
{
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer resultado = new StringBuffer();
String linea = "";
while ((linea = reader.readLine()) != null) {
resultado.append(linea);
}
String resultadoString = resultado.toString();
JSONObject resultadoJSON = new JSONObject(resultadoString);
int id = resultadoJSON.getInt("Id");
String nombre = resultadoJSON.getString("Nombre");
String correo = resultadoJSON.getString("Email");
return "Id: " + id + " - " + "Nombre: " + nombre + " - " + "Correo: " + correo;
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally {
if(connection != null)
{
connection.disconnect();
}
try
{
if(reader != null)
{
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(String result)
{
Log.i("ServicioRest","onPostExecute");
Mensaje.setText(result);
}
@Override
protected void onPreExecute()
{
Log.i("ServicioRest","onPreExecute");
info.setText("Se esta obteniendo la información.");
}
}
What am I doing wrong?