//--------参数一为数据接口--------参数二为上下文------参数三为json解析接口类
public static void getdata(final String path, Context ctx, final Jsoncallbask jc) {
if (Httputil.isConn(ctx)) {
AsyncTask<Void, Void, String> asyncTask = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... voids) {
try {
URL url = new URL(path);
HttpURLConnection hur = (HttpURLConnection) url.openConnection();
hur.setRequestMethod("GET");
hur.setReadTimeout(5000);
hur.setConnectTimeout(5000);
int code = hur.getResponseCode();
if (code == 200) {
InputStream stream = hur.getInputStream();
String s = Stringutils.convertStreamToString(stream, "utf-8");
return s;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
jc.getjson(s);
}
};
asyncTask.execute();
} else {
Httputil.showNoNetWorkDlg(ctx);
}