Android HttpConnect
2010-10-19 20:17:34 来源:WEB开发网核心提示:(httpResponse.getStatusLine().getStatusCode() == 200) { String strResult = EntityUtils.toString(httpResponse.getEntity()); mtv1.setText(strResult); } } catch (E
(httpResponse.getStatusLine().getStatusCode() == 200) { String strResult =
EntityUtils.toString(httpResponse.getEntity()); mtv1.setText(strResult); } }
catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } } );
mb2.setOnClickListener(new Button.OnClickListener() { public void onClick(View
v) { // TODO Auto-generated method stub String uriAPI =
"http://www.dubblogs.cc:8751/android/test/api/get/index.php?str=I+am+Get+String";
HttpGet httpRequest = new HttpGet(uriAPI); try { HttpResponse httpResponse = new
DefaultHttpClient().execute(httpRequest); if
(httpResponse.getStatusLine().getStatusCode() == 200) { String strResult =
EntityUtils.toString(httpResponse.getEntity()); strResult =
eregi_replace("(
||
|
)", "", strResult); mtv1.setText(strResult); } }
catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } } ); }
protected String eregi_replace(String strFrom, String strTo, String strTarget) {
// TODO Auto-generated method stub String strPattern = "(?!)" + strFrom; Pattern
p = Pattern.compile(strPattern); Matcher m = p.matcher(strTarget); if (m.find())
{ return strTarget.replaceAll(strFrom, strTo); } else { return strTarget; } }
}
view plaincopy to clipboardprint?
1. < ?xml version="1.0" encoding="utf-8"?>
2. < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. android:orientation="vertical"
4. android:layout_width="fill_parent"
5. android:layout_height="fill_parent"
6. >
7. < TextView
8. android:id="@+id/tv1_id"
9. android:layout_width="fill_parent"
10. android:layout_height="wrap_content"
11. android:text="@string/hello"
12. />
13. < Button
14. android:id="@+id/b1_id"
15. android:layout_width="fill_parent"
16. android:layout_height="wrap_content"
Tags:Android HttpConnect
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接