HttpClient
来源:互联网 发布:table用js做点击事件 编辑:程序博客网 时间:2024/06/06 04:16
@Override
protected void onPreExecute() {
super.onPreExecute();
Toast.makeText(MainActivity.this,”正在加載中”,Toast.LENGTH_LONG).show();
}
@Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); } @Override protected void onPostExecute(String s) { super.onPostExecute(s); Log.i("xxxxxxxxxxxxx", s.toString()); } @Override protected String doInBackground(String... params) { //獲取接口地址 String url = params[0]; //創建網絡請求方式 HttpClient client = new DefaultHttpClient(); //創建請求方式 HttpGet get = new HttpGet(url); //通過網絡請求對象執行請求 try { HttpResponse response = client.execute(get); //判斷響應碼 if (response.getStatusLine().getStatusCode() == 200) { InputStream inputStream = response.getEntity().getContent(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ( (len = inputStream.read(buffer)) != -1 ){ bos.write(buffer, 0, len); } inputStream.close(); bos.close(); String json = bos.toString(); return json; } } catch (Exception e) { e.printStackTrace(); } return null; }}
阅读全文
0 0
- HttpClient
- HttpClient
- httpClient
- HttpClient
- HttpClient
- HttpClient
- HttpClient
- HttpClient
- HttpClient
- HttpClient
- HttpClient
- httpclient
- httpclient
- HttpClient
- HttpClient
- httpclient
- httpclient
- HttpClient
- linux网络编程中INADDR_ANY的含义
- gulp使用
- [Leetcode] 372. Super Pow 解题报告
- nuget 导致 vs hang死
- 工作日记2017.08.21 Google Guava
- HttpClient
- leetcode 409. Longest Palindrome
- Android源码目录结构详解
- opengl对图像进行模糊处理
- ajaxfileupload文件上传插件,解决再次提交文件流置空的问题
- 常见状态码
- 汉明码详细讲解
- collectionView 无限轮播设计思路
- http://www.revolvermaps.com/