Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String acessar(String endereco) throws IOException {
- URL url = new URL("http://pokeapi.co/api/v2/pokemon/1/");
- HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
- urlConnection.setRequestMethod("GET");
- urlConnection.connect();
- InputStream inputStream = urlConnection.getInputStream();
- if (inputStream == null) {
- return null;
- }
- BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
- String linha;
- StringBuffer buffer = new StringBuffer();
- while ((linha = reader.readLine()) != null) {
- buffer.append(linha + "n");
- }
- if (buffer.length() == 0) {
- return null;
- }
- if (urlConnection != null) {
- urlConnection.disconnect();
- }
- if (reader != null) {
- try {
- reader.close();
- } catch (final IOException e) {
- Log.e("Erro", "Erro fechando o stream", e);
- }
- }
- return "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement