<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="request btn"/><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /></LinearLayout>
Package COM. oppo; import Org. apache. HTTP. httpentity; import Org. apache. HTTP. httphost; import Org. apache. HTTP. httpresponse; import Org. apache. HTTP. client. clientprotocolexception; import Org. apache. HTTP. client. httpclient; import Org. apache. HTTP. client. methods. httpget; import Org. apache. HTTP. conn. params. connrouteparams; import Org. apache. HTTP. impl. client. defaulthttpclient; import Org. apache. HTTP. params. basicht Tpparams; import Org. apache. HTTP. params. httpparams; import android. app. activity; import android.net. proxy; import android. OS. bundle; import android. util. log; import android. view. view; import android. widget. button; import Java. io. bufferedreader; import Java. io. ioexception; import Java. io. inputstream; import Java. io. inputstreamreader; public class httptestactivity extends activity {protected static final strin G tag = "httptestactivity"; private button requestbtn; private httpresponse; private httpentity; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); requestbtn = (button) findviewbyid (R. id. BTN); requestbtn. setonclicklistener (new view. onclicklistener () {@ override public void onclick (view v) {// get Proxy Information String host = proxy. gethost (getapplicationcontext (); int Port = proxy. getport (getapplicationcontext (); log. D (TAG, "[createhttpclient] proxyhost =" + host); log. D (TAG, "[createhttpclient] proxyport =" + port); // sets the HTTP connection information of the host. httphost = new httphost (host, Port ); httpparams = new basichttpparams (); httpparams. setparameter (connrouteparams. default_proxy, httphost); httpget HTTP Get = new httpget ("http://www.baidu.com"); httpclient = new publish (httpparams); inputstream = NULL; try {httpresponse = httpclient.exe cute (httpget); httpentity = httpresponse. getentity (); inputstream = httpentity. getcontent (); bufferedreader reader = new bufferedreader (New inputstreamreader (inputstream); string result = ""; string line = ""; while (line = Reader. Readline ())! = NULL) {result + = Result + line;} system. out. println (result);} catch (clientprotocolexception e) {e. printstacktrace ();} catch (ioexception e) {e. printstacktrace ();} finally {/* try {inputstream. close ();} catch (ioexception e) {e. printstacktrace ();}*/}}});}}
Don't forget this sentence. You must have the intent access permission.
<uses-permission android:name="android.permission.INTERNET"/>
Blog has moved to http://marspring.mobi/