0

Приложение отправляет запрос на сервер и получает строку JSon.

Все работает на версии андроид 2.3.7 и 4.0.2, а на версии 4.2.2 вылетает следующая ошибка:

java.net.MalformedURLException: Protocol not found:

   try {
        URL url = new URL(url_zapr);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setReadTimeout(100000);
        connection.setConnectTimeout(100000);
        connection.setRequestMethod("GET");
        connection.setInstanceFollowRedirects(true);
        connection.setUseCaches(false);
        connection.setDoInput(true);
        int responseCode = connection.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_OK) { // 200 OK
            inputstream = connection.getInputStream();
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            int read = 0;
            while ((read = inputstream.read()) != -1) { bos.write(read); }
            byte[] result = bos.toByteArray();
            bos.close();
            data = new String(result);
        } else {data = connection.getResponseMessage() + " . Error Code : " + responseCode;}
        connection.disconnect();
        return data;
    } catch (MalformedURLException e) { e.printStackTrace();         Log.d(LOG_TAG,"e1= "+ e.toString());
    }
    catch (IOException e) { e.printStackTrace(); Log.d(LOG_TAG,"e2"+ e.toString());}
    finally { if (inputstream != null) { Log.d(LOG_TAG,"e3"); inputstream.close(); }}

В чем может быть проблема?

3
  • работа с сетью в UI??
    – Gorets
    23 мар 2015 в 9:01
  • xxx.ru/mapi/…
    – kaaa
    23 мар 2015 в 9:15
  • проблема была в отсутствии WWW. Подставил и все заработало.
    – kaaa
    23 мар 2015 в 9:24

1 ответ 1

2

Гугоо-о-ол! Ауу ты где?

Ваш URI - не URI (c).

Add http:// before the www... or https://.

public String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";

alt text

1
  • добавил еще www в строку и все заработало. Благодарю!
    – kaaa
    23 мар 2015 в 9:22

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.