package com.bawie.com.shanggeyueyuekao; import android.os.AsyncTask; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; /** * Created by Administrator on 2018/1/12 0012. */ public class ListMyTask extends AsyncTask<String,Void,String> { private ListIcall listIcall; String str=""; public ListMyTask(ListIcall listIcall) { this.listIcall = listIcall; } @Override protected String doInBackground(String... strings) { try { URL url=new URL(strings[0]); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setConnectTimeout(5000); urlConnection.setReadTimeout(5000); urlConnection.setRequestMethod("GET"); int responseCode = urlConnection.getResponseCode(); if(responseCode==200){ InputStream inputStream = urlConnection.getInputStream(); str = ListStreamToString.listStreamToString(inputStream,"utf-8"); } } catch (Exception e) { e.printStackTrace(); } return str; } @Override protected void onPostExecute(String s) { super.onPostExecute(s); listIcall.ListUpdatejson(s); } public interface ListIcall{ void ListUpdatejson(String strjson); } }
MyTask
最新推荐文章于 2022-09-21 22:07:55 发布