httpUrlConncetion请求网络

private void getAddress() {
String path = "http://img.my.csdn.net/uploads/201407 /26/1406383242_3127.jpg";
try {
// 得到路径
URL url = new URL(path);
// 打开链接
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
// 设置连接超时时间
connection.setConnectTimeout(2000);
// 设置超时读取时间
connection.setReadTimeout(2000);
// 获取实体类型
String type = connection.getContentType();
// 获取长度
int contentLength = connection.getContentLength();
// 获取请求吗
int responseCode = connection.getResponseCode();

        if (responseCode == 200) {
            InputStream inputStream = connection.getInputStream();
            decodeStream = BitmapFactory.decodeStream(inputStream);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

你可能感兴趣的:(httpUrlConncetion请求网络)