80,350
社区成员
发帖
与我相关
我的任务
分享
private String getPDAServerData(String url){
HttpClient client = new DefaultHttpClient();
HttpPost request;
String out="";
try {
request = new HttpPost(new URI(url));
HttpResponse response = client.execute(request);
// 判断请求是否成功
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
if (entity != null) {
out = EntityUtils.toString(entity);
//new AlertDialog.Builder(this).setMessage(out).create().show();
}
}
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return out;
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView1 = (TextView)this.findViewById(R.id.msg);
// id,title,thumb,description,inputtime
String str = getPDAServerData(url);
String []arr = str.split("&");//这里是自定义的字符解析,可以忽略
String html = "";
for(int i=0;i<arr.length;i++){
String []arr2 = arr[i].split("|");
html += "<img src=\""+arr[2]+"\" width=\"80\" height=\"80\"/>"+arr2[1];
if(i%2!=0)
html+="<br>";
}
CharSequence charSequence = Html.fromHtml(html);
textView1.setText(charSequence);
}