展会信息港展会大全

使用HttpClient发送HTTP请求。记得需要在AndroidManifes...
来源:互联网   发布日期:2016-01-14 11:33:16   浏览:1648次  

导读:uses-permission android:name=android.permission.INTERNET / HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(new HttpGet(URL)); StatusLine statusLine = response.getStatusLine(); if(statusLine.getSt...

<uses-permission android:name="android.permission.INTERNET" />

HttpClient httpclient = new DefaultHttpClient();

HttpResponse response = httpclient.execute(new HttpGet(URL));

StatusLine statusLine = response.getStatusLine();

if(statusLine.getStatusCode() == HttpStatus.SC_OK){

ByteArrayOutputStream out = new ByteArrayOutputStream();

response.getEntity().writeTo(out);

String responseString = out.toString();

out.close();

//..more logic

} else {

//Closes the connection.

response.getEntity().getContent().close();

throw new IOException(statusLine.getReasonPhrase());

}

赞助本站

人工智能实验室

相关热词: android开发 android教程

相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港