標籤:影響 activity store ogg final htm get請求 依賴 als
1.添加依賴: compile ‘com.yanzhenjie.nohttp:nohttp:1.1.1‘
2.註冊初始化
NoHttp.initialize(this);
Logger.setDebug(true);// 開啟NoHttp的偵錯模式, 配置後可看到請求過程、日誌和錯誤資訊。上線後改為false 不然影響效能
Logger.setTag("NoHttpSample");// 設定NoHttp列印Log的tag。
3.Nohttp的get請求
RequestQueue requestQueue = NoHttp.newRequestQueue();
Request<String> request = NoHttp.createStringRequest("http://c.m.163.com/nc/article/headline/T1348647909107/" + START + "-" + SUM + ".html", RequestMethod.GET);
requestQueue.add(0, request, new OnResponseListener<String>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<String> response) {
String json = response.get();//得到請求資料
}
@Override
public void onFailed(int what, Response<String> response) {
}
@Override
public void onFinish(int what) {
}
});
4.Nohttp請求圖片
final Request<Bitmap> request = NoHttp.createImageRequest("https://ps.ssl.qhimg.com/sdmt/166_135_100/t01b77a38c118a9967e.jpg", RequestMethod.GET);
requestQueue.add(2, request, new OnResponseListener<Bitmap>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<Bitmap> response) {
Bitmap bitmap = response.get();
Log.e("ABC",bitmap.toString());
icon.setImageBitmap(bitmap);
}
@Override
public void onFailed(int what, Response<Bitmap> response) {
}
@Override
public void onFinish(int what) {
}
});
5.Nohttp的post請求
Request<String> request = NoHttp.createStringRequest("http://apicloud.mob.com/appstore/horoscope/day", RequestMethod.POST);
request.add("key", "1d120467e646b");
request.add("date", "1994-11-09");
request.add("hour", "1");
requestQueue.add(1, request, MainActivity.this);
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<String> response) {
String json = response.get();
switch (what){
case 0:
Log.e("TAG","get:::"+json);
show.setText(json);
break;
case 1:
Log.e("TAG","post:::"+json);
show.setText(json);
break;
}
}
@Override
public void onFailed(int what, Response<String> response) {
}
@Override
public void onFinish(int what) {
}
6.NoHttp網路請求只包含四個方法:
1.開始請求
2.得到資料
3.得到請求資料
4.請求結束
NoHttp的使用