Pessoal, estou tentando ler um conteudo (texto) que retorna apos eu consultar um cnpj de um cliente.
eu renderizo em um iframe mas ao tentar ler o o iframe ele não deixa pois é de um site externo.
Estou tentando então usar HttpClient para tentar pegar esse retorno mas o que retorna para mim é somente
a estrutura da pagina html body etc…
Quando colo a url no navegador da certo mas se eu tentar pegar o retorno pelo java traz a estrutura da pagina .
como posso fazer? estou querendo apenas ler e não modificar!
public String consultarCnpjCliente() throws MalformedURLException, IOException {
String url = "http://mashups.empresa.com.br/SOAWebClient/WebClient.ResultScreen.aspx";
HttpClient client = new HttpClient();
// Create a method instance.
GetMethod method = new GetMethod(url);
// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
StringBuilder retorno = new StringBuilder();
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
retorno.append("Method failed: ").append(method.getStatusLine());
}
// Read the response body.
byte[] responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
retorno.append(new String(responseBody));//<------ tinha que pegar o retorno e não a estrutura
} catch (HttpException e) {
retorno.append("Fatal protocol violation: ").append(e.getMessage());
} catch (IOException e) {
retorno.append("Fatal transport error: ").append(e.getMessage());
} finally {
// Release the connection.
method.releaseConnection();
}
return retorno.toString();
}