Skip to content

Instantly share code, notes, and snippets.

@henrystivens
Created July 26, 2013 21:43
Show Gist options
  • Save henrystivens/6092473 to your computer and use it in GitHub Desktop.
Save henrystivens/6092473 to your computer and use it in GitHub Desktop.
Ejecutar URL
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