package com.example.asynctask;
import java.io.InputStream;
import java.net.URL;
/**
* Created by HP on 2017/11/29.
*/
public class HttpURLConnection {
public static InputStream URLConnection(String path){
InputStream inputStream = null;
try {
URL url = new URL(path);
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
int code = connection.getResponseCode();
if(code == 200){
inputStream = connection.getInputStream();
return inputStream;
}
} catch (Exception e) {
e.printStackTrace();
}
return inputStream;
}
}
import java.io.InputStream;
import java.net.URL;
/**
* Created by HP on 2017/11/29.
*/
public class HttpURLConnection {
public static InputStream URLConnection(String path){
InputStream inputStream = null;
try {
URL url = new URL(path);
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
int code = connection.getResponseCode();
if(code == 200){
inputStream = connection.getInputStream();
return inputStream;
}
} catch (Exception e) {
e.printStackTrace();
}
return inputStream;
}
}