package Network;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import demo.text.com.mvpdemo.MainActivity;

/**
* Created by Administrator on 2016/5/20.
*/
public class Checknetstate {


public static String getjson(String str) {

String json_str = "";
try {

URL url = new URL(str);
HttpURLConnection connection = null;
connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
connection.setRequestMethod("GET");
connection.connect();
if (connection.getResponseCode() == 200) {
InputStream inputStream = connection.getInputStream();
//包装流
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String readline = "";
StringBuffer buffer = new StringBuffer();
//按行读取
while ((readline = reader.readLine()) != null) {
buffer.append(readline);
}
json_str = buffer.toString();
}
} catch (Exception e) {
e.printStackTrace();
}


return json_str;
}
}