Foros del Web » Programación para mayores de 30 ;) » Java »

Acceder al xml de un servicio web

Estas en el tema de Acceder al xml de un servicio web en el foro de Java en Foros del Web. Hola queria preguntaros como accedeis al xml de un servicio web, yo hasta ahora estoy usando httpclient pero me da errores de vez en cuando. ...
  #1 (permalink)  
Antiguo 03/06/2008, 09:23
 
Fecha de Ingreso: abril-2008
Mensajes: 17
Antigüedad: 16 años
Puntos: 0
Acceder al xml de un servicio web

Hola queria preguntaros como accedeis al xml de un servicio web, yo hasta ahora estoy usando httpclient pero me da errores de vez en cuando. Lo hago asi:

public class ObtenerXML {


public static String realizarAccion(String url) throws HttpException {

String responseBody = null;

// Create an instance of HttpClient.
HttpClient client = new HttpClient();
//client.getParams().setParameter("http.protocol.con tent-charset", "UTF-8");


// Create a method instance.
GetMethod method = new GetMethod(url);

// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.R ETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
// method.getParams().setParameter("http.protocol.con tent-charset", "UTF-8");


try {
// Execute the method.
int statusCode = client.executeMethod(method);

if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}

// Read the response body.
responseBody = method.getResponseBodyAsString();

// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data


} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}

return ((responseBody));
}

}

Si conoceis alguna forma mas eficiente de hacerlo os lo agrdeceria.

Muchas gracias!!
  #2 (permalink)  
Antiguo 03/06/2008, 17:51
Avatar de jam1138
/** @package Moderador */
 
Fecha de Ingreso: julio-2004
Ubicación: sèveR led onieR lE
Mensajes: 9.368
Antigüedad: 19 años, 9 meses
Puntos: 102
Respuesta: Acceder al xml de un servicio web

... y eso es... JAVA. Tema movido.
__________________
٩(͡๏̯͡๏)۶
» Cómo hacer preguntas de manera inteligente «

"100 años después, la revolución no es con armas, es intelectual y digital"
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:15.