解决方案 »

  1.   


    try{
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(img_path);
    HttpResponse httpResponse = httpClient.execute(httpGet);
    if(httpResponse.getStatusLine().getStatusCode()==200){
    HttpEntity entity = httpResponse.getEntity();
    byte[] data = EntityUtils.toByteArray(entity);
    bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
    handler.sendEmptyMessage(10001);
    }
    }catch(Exception e){
    }这个是获取网络图片的列子,你可以把data换成你想要的数据,比如stream流等
      

  2.   


    new Thread(new Runnable() { @Override
    public void run() {
    //你的请求
    }
    }).start();
      

  3.   

    要么就在子线程中请求,要么加上下面这些代码
     if (Build.VERSION.SDK_INT >= 11) {
          StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
       StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
      }
      

  4.   


    那可以帮我看一下不,这样的例子
    public static String postRequest(String url,Map<String ,String> param)throws Exception{
    HttpPost post = new HttpPost(url);
    //如果传递多个参数可以对传递额参数进行封装
    List<NameValuePair> par = new ArrayList<NameValuePair>();
    for(String key:param.keySet()){
    //封装请求参数
    par.add(new BasicNameValuePair(key, param.get(key)));
    }
    //设置请求参数
    post.setEntity(new UrlEncodedFormEntity(par,"gbk"));
    //发送post请求
    HttpClient http = new DefaultHttpClient(); 
    try {
    HttpResponse response = http.execute(post);
    if(response.getStatusLine().getStatusCode()==200){
    String result = EntityUtils.toString(response.getEntity());
    Log.v("result", "post请求成功!");
    Log.v("result", result);
    return result;
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    //Log.v("result", "post请求失败!");
    return null;
    }HttpResponse response = http.execute(post);执行到这里就报错了
      

  5.   

    http://www.linuxidc.com/Linux/2011-08/40654.htm
      

  6.   

    方法一、Thread + Handler 参数可用全局变量
    方法二、AsyncTask ,可以传入参数