android 中的url操作步骤
1、获取HttpClient对象
2、获取HttpGet对象,通过HttpGet对象可以对请求设置参数
3、通过HttpClient对象的excute方法得到HttpResponse对象
4、把HttpResponse对象获取返回的值

摘自android的document

/**     * Pull the raw text content of the given URL. This call blocks until the     * operation has completed, and is synchronized because it uses a shared     * buffer {@link #sBuffer}.     *     * @param url The exact URL to request.     * @return The raw content returned by the server.     * @throws ApiException If any connection or server error occurs.     */    protected static synchronized String getUrlContent(String url) throws ApiException {        if (sUserAgent == null) {            throw new ApiException("User-Agent string must be prepared");        }        // Create client and set our specific user-agent string        HttpClient client = new DefaultHttpClient();        HttpGet request = new HttpGet(url);        request.setHeader("User-Agent", sUserAgent);        try {            HttpResponse response = client.execute(request);            // Check if server response is valid            StatusLine status = response.getStatusLine();            if (status.getStatusCode() != HTTP_STATUS_OK) {                throw new ApiException("Invalid response from server: " +                        status.toString());            }            // Pull content stream from response            HttpEntity entity = response.getEntity();            InputStream inputStream = entity.getContent();            ByteArrayOutputStream content = new ByteArrayOutputStream();            // Read response into a buffered stream            int readBytes = 0;            while ((readBytes = inputStream.read(sBuffer)) != -1) {                content.write(sBuffer, 0, readBytes);            }            // Return result from buffered stream            return new String(content.toByteArray());        } catch (IOException e) {            throw new ApiException("Problem communicating with API", e);        }    }

更多相关文章

  1. Android中 ScrollView(ListView)中嵌套ListView时显示不全的简便解
  2. Android(安卓)设备+APP+号码信息
  3. Android设备硬件序列号(SN、串号)分析
  4. Android多媒体学习三:实现自己的Camera
  5. Android之Handler用法总结
  6. 【Android】如何让跑马灯跑起来-控件请求焦点
  7. Android根据文件路径使用File类获取文件相关信息
  8. android获取GPS位置信息
  9. android 中的几种目录

随机推荐

  1. [Android(安卓)实例教程] Android,谁动了
  2. android属性之Layout_weight
  3. android 开发 xml绘制Selector 一 基础篇
  4. Android隐藏状态栏和标题栏,相当于全屏效
  5. Android界面设计中的常见属性
  6. Android(安卓)中从res/values/strings.xm
  7. 值得推荐的Android应用性能检测工具列表(
  8. Android布局文件layout.xml的一些属性值
  9. Android(安卓)自定义日历控件
  10. Android(安卓)Layout 布局属性