当我从android studio运行TestUtil类时,我得到以下异常 . 但是如果我从eclipse运行它可以正常工作 .

java.net.SocketException:java.net.SocketInputStream.read(SocketInputStream.java:189)中的连接重置位于sun.security.ssl.InputRecord.readFully的java.net.SocketInputStream.read(SocketInputStream.java:121) InputRecord.java:442)sun.security.ssl.InputRecord.read(InputRecord.java:480)at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)at sun.security.ssl.SSLSocketImpl.performInitialHandshake (SSLSocketImpl.java:1312)sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)at sun.net.www.protocol . https.HttpsClient.afterConnect(HttpsClient.java:515)at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection . java:1299)at.com.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)at com.XYZ.android . com.XYZ.android.cmpi.tests.TestUtil.main中的cmpi.util.RestUtil.get(RestUtil.java:36)(TestUtil.java:15)

public class TestUtil {

    public static void main(String[] args) throws MalformedURLException {
        String response = RestUtil.get(new URL(RestUtil.getURL()));
        print(response);
    }

    public static void print(Object o) {
        out.print(o);
    }
}

//

public class RestUtil {



        public final static String USER_AGENT = "Mozilla/5.0";

        public static String get(URL url) {
            StringBuilder sb = new StringBuilder();
            HttpURLConnection connection = null;
            try {
                connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("GET");

                BufferedReader br = new BufferedReader(new InputStreamReader(
                        connection.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) {
                    sb.append(line);
                }

                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                connection.disconnect();
            }
            return sb.toString();
        }

        public static String getURL() {
            // returns URL
        }
    }

当我从android studio运行时,我不知道为什么我会遇到这个异常,而不是来自Eclipse .