HttpClient
HttpClient本身也不是android的接口,是apache的对于网络编程的接口 该接口代码也未简化,但语义上更接近人的自然语言
pubic void getDataWithHttpClient(){
Thread t = new Thread (){
public void run(){
String path = "www.baidu.com/content.rar" ;
HttpClient hc = new DefaultHttpClient();
HttpPost hp = new HttpPost(path);
BasicNameValuePair bnvp = new BasicNameValuePair("name" , name);
Lsit< BasicNameValuePair> list = new ArrayList< BasicNameValuePair> ();
list . add(bnvp);
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list );
hp. setEntity(entity);
HttpResponse hr = hc. execute(hp);
if (hr. getStatusLine(). getStatusCode()== 200 ){
InputStream is = hr. getEntity(). getContent();
}
}
};
t. start();
}
android异步AsncHttpClient
gitHub对于Apache的HttpClient封装
public void getDataWithAsncHttpClient (){
AsncHttpClient ahc = new AscHttpClient();
String url = "www.baidu.com/xx?name=xx&pwd=xxx" ;
ahc.get (url, new AsycHttpResponseHandler(){
public void onSuccess (int statusCode, Header[] headers, byte [] responseBody){
}
public void onFailure (int statusCode, Header[] headers byte [] responseBody, Throwable error){
}
});
RequestParams params = new RequestParams();
params .add("name" , name);
params .add("pwd" , pwd);
ahc.post(url, params ,new AyncHttpResponseHandler(){
});
}