在AndroidManifest.xml中要加入可以使用網路的權限
< uses-permission android:name="android.permission.INTERNET" >< /uses-permission >
在程式部份
//for Http Get
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
public void executeHttpGet() throws Exception {
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(網址);
HttpResponse response = client.execute(request);
String retSrc = EntityUtils.toString(response.getEntity());
System.out.println(retSrc);
} finally {
}
}
2 則留言:
為何在執行.execute(request)就例外了
為何在.execute(request)就跑出例外了
張貼留言