Android 开发 Tips

1. Http 用Post传参数问题:

新版本的android sdk 禁止在主线程内做post操作,需要另起一个线程进行。

public class HttpPostTask extends AsyncTask<HttpPost, Void, String>{


@Override
protected String doInBackground(HttpPost... arg0) {
// TODO Auto-generated method stub
HttpPost postRequest = arg0[0];
HttpResponse response = null;
String result = null;
try {
response = new DefaultHttpClient().execute(postRequest);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}

}

posted on 2013-10-17 11:09  小嘟  阅读(173)  评论(0)    收藏  举报

导航