Created
July 26, 2013 21:43
-
-
Save henrystivens/6092473 to your computer and use it in GitHub Desktop.
Ejecutar URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String consultar(String strUrl) throws Exception { | |
String xml = ""; | |
String inputLine = ""; | |
try { | |
// Install the custom authenticator | |
Authenticator.setDefault(new MyAuthenticator()); | |
//Conexion a la URL | |
URL url = new URL(strUrl); | |
URLConnection wsConnection = url.openConnection(); | |
//Lector de de la respuesta | |
BufferedReader br = new BufferedReader(new InputStreamReader(wsConnection.getInputStream())); | |
//Crea la cadena con el contenido de la respuesta | |
while ((inputLine = br.readLine()) != null) { | |
xml += inputLine; | |
} | |
//Cierra el lector | |
br.close(); | |
} catch (MalformedURLException me) { | |
System.out.println("MalformedURLException: " + me); | |
throw new Exception("MalformedURLException: " + me); | |
} catch (IOException ioe) { | |
System.out.println("IOException: " + ioe); | |
throw new Exception("IOException: " + ioe); | |
} | |
return xml; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment