从网络获取数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从网络获取数据相关的知识,希望对你有一定的参考价值。
HttpClient httpClient = new DefaultHttpClient(); HttpGet httpPost = new HttpGet("http://www.facebookwidgets4all.com/clients/thumbsupchamp/thumbsupview.php?top=5"); httpPost.addHeader("Content-Type","application/x-www-form-urlencoded"); HttpResponse httpResponse; try { httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity !=null) { // Convert Stream to String result = convertStreamToString(inputStream); inputStream.close(); httpClient =null; httpPost.abort(); } } catch (ClientProtocolException e) { e.printStackTrace(); e.printStackTrace(); e.printStackTrace(); } int count = 0; ArrayList<String> arrList = new ArrayList<String>(); int index = 0; while(str.contains("<br />")){ str1 = str.substring(0, str.indexOf("<br />")); str = str.substring(str.indexOf("<br />")+"<br />".length()); arrList.add(str1); count++; } _dataList = new ArrayList<Data>(); StringTokenizer st ; for(int i = 0;i < arrList.size();i++){ Data _data = new Data(); while(st.hasMoreTokens()){ _data._initial = st.nextToken().replace('"',' '); _data._email = st.nextToken().replace('"',' '); _data._smartPhone = st.nextToken().replace('"',' '); _data._country = st.nextToken().replace('"',' '); _data._wpm = st.nextToken().replace('"',' '); Log.i("array ", ""+ _data._initial + " " + _data._email + " " + _data._smartPhone); _dataList.add(_data); } }
以上是关于从网络获取数据的主要内容,如果未能解决你的问题,请参考以下文章
从多个社交网络(Facebook 和 Linkedin...)获取统一配置文件的数据库方案