// To use these Internet methods, AndroidManifest.xml must have the
// following permission:
// <uses-permission android:name="android.permission.INTERNET"/>
URI myURI = null;
try {
myURI = new URI("www.webserver.org");
} catch (URISyntaxException e) {
// Deal with it
}
HttpClient httpClient = new DefaultHttpClient();
HttpGet getMethod = new HttpGet(myURI);
HttpResponse webServerResponse = null;
try {
webServerResponse = httpClient.execute(getMethod);
} catch (ClientProtocolException e) {
// Deal with it
} catch (IOException e) {
// Deal with it
}
HttpEntity httpEntity = webServerResponse.getEntity();
if (httpEntity != null) {
BufferedReader br = new BufferedReader(new InputStreamReader(
entity.getContent()));
String line = null;
response.setText("");
while ((line = br.readLine()) != null) {
// 使用response文本框显示服务器响应
response.append(line + "\n");
}
}
android中发起GET请求
最新推荐文章于 2025-03-06 21:54:16 发布