77import org .apache .http .HttpEntity ;
88import org .apache .http .HttpResponse ;
99import org .apache .http .client .HttpClient ;
10+ import org .apache .http .client .methods .HttpEntityEnclosingRequestBase ;
11+ import org .apache .http .client .methods .HttpGet ;
1012import org .apache .http .client .methods .HttpPost ;
13+ import org .apache .http .client .methods .HttpRequestBase ;
1114import org .apache .http .conn .ClientConnectionManager ;
1215import org .apache .http .conn .scheme .PlainSocketFactory ;
1316import org .apache .http .conn .scheme .Scheme ;
@@ -28,6 +31,11 @@ public Client(HttpClient client) {
2831 mClient = client ;
2932 }
3033
34+ public static ClientExecutor get (String url , CallRet ret ) {
35+ Client client = Client .defaultClient ();
36+ return client .get (client .makeClientExecutor (), url , ret );
37+ }
38+
3139 public ClientExecutor call (ClientExecutor client , String url , HttpEntity entity , CallRet ret ) {
3240 Header header = entity .getContentType ();
3341 String contentType = "application/octet-stream" ;
@@ -47,26 +55,30 @@ public ClientExecutor call(ClientExecutor client, String url, String contentType
4755 return execute (client , httppost , ret );
4856 }
4957
58+ public ClientExecutor get (ClientExecutor client , String url , CallRet ret ) {
59+ return execute (client , new HttpGet (url ), ret );
60+ }
61+
5062 public ClientExecutor makeClientExecutor () {
5163 return new ClientExecutor ();
5264 }
5365
54- protected ClientExecutor execute (ClientExecutor client , HttpPost httpPost , final CallRet ret ) {
55- client .setup (httpPost , ret );
66+ protected ClientExecutor execute (ClientExecutor client , HttpRequestBase httpRequest , final CallRet ret ) {
67+ client .setup (httpRequest , ret );
5668 client .execute ();
5769 return client ;
5870 }
5971
60- protected HttpResponse roundtrip (HttpPost httpPost ) throws IOException {
61- httpPost .setHeader ("User-Agent" , Conf .USER_AGENT );
62- return mClient .execute (httpPost );
72+ protected HttpResponse roundtrip (HttpRequestBase httpRequest ) throws IOException {
73+ httpRequest .setHeader ("User-Agent" , Conf .USER_AGENT );
74+ return mClient .execute (httpRequest );
6375 }
6476
6577 public class ClientExecutor extends AsyncTask <Object , Object , Object > implements ICancel {
66- HttpPost mHttpPost ;
78+ HttpRequestBase mHttpRequest ;
6779 CallRet mRet ;
68- public void setup (HttpPost httpPost , CallRet ret ) {
69- mHttpPost = httpPost ;
80+ public void setup (HttpRequestBase httpRequest , CallRet ret ) {
81+ mHttpRequest = httpRequest ;
7082 mRet = ret ;
7183 }
7284 public void upload (long current , long total ) {
@@ -76,10 +88,10 @@ public void upload(long current, long total) {
7688 @ Override
7789 protected Object doInBackground (Object ... objects ) {
7890 try {
79- HttpResponse resp = roundtrip (mHttpPost );
91+ HttpResponse resp = roundtrip (mHttpRequest );
8092 int statusCode = resp .getStatusLine ().getStatusCode ();
8193 if (statusCode == 401 ) { // android 2.3 will not response
82- return new Exception (resp . getStatusLine (). getReasonPhrase () );
94+ return new Exception ("unauthorized!" );
8395 }
8496 byte [] data = EntityUtils .toByteArray (resp .getEntity ());
8597
0 commit comments