网络相关
异步应用
- 包:AsyncHttlClient
代码: get: ``` //获取列表
String url = Constant.mettinglist; AsyncHttpClient client = new AsyncHttpClient(); client.get(getApplicationContext(), url, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { String res = new String(bytes); listData = JsonUtil.getMeetingList(res); Log.e("arilpan", "success 返回值" + res); } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { String res = new String(bytes); Log.e("arilpan", "metting list fail " ); throwable.printStackTrace(); } });
post
AsyncHttpClient client = new AsyncHttpClient();
client.post(url, keyMapParam, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { Log.e("arilpan", "success 返回值" + new String(bytes)); } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { Log.e("arilpan", "fail 返回值 code" + i); throwable.printStackTrace(); } });
```
- 分析
- 失败:onFrailure 第一个参数返回HttpStateCode超时返回0 403:cz.msebera.android.httpclient.client.HttpResponseException: Forbidden
- 成功:bytes即为响应消息