/**
* @author AT
* Http网络类
* 此处方法需要是公开的 public
* 如果使用同步(Sync)请方法,请在子线程执行这个操作,否则非常有可能报
*/
public void btnClickRequest(View v){
FinalHttp fh = new FinalHttp();
//
fh.get(url, headers, params, callBack);
//
fh.get(url, params, callBack);
//
fh.post(url, headers, entity, contentType, callBack);
//
fh.post(url, entity, contentType, callBack);
//
fh.post(url, params, callBack);
//
fh.post(url, callBack);
//
fh.addHeader(header, value);添加头部
//
fh.configCookieStore(cookieStore); 设置cookie
//
fh.configUserAgent(userAgent);
//
fh.configTimeout(timeout);设置超时
//
fh.configSSLSocketFactory(sslSocketFactory);配置https请求
//
fh.configRequestExecutionRetryCount(count);配置网络异常自动重复连接请求次数
AjaxParams param = new AjaxParams();
param.put("city", "北京");
fh.get("http://wthrcdn.etouch.cn/weather_mini",param, new AjaxCallBack<Object>(){
@Override
public void onFailure(Throwable t, int errorNo, String strMsg) {
super.onFailure(t, errorNo, strMsg);
Toast.makeText(FinalActivityTest.this, "onFailure: "+strMsg, Toast.LENGTH_SHORT).show();
}
@Override
public void onLoading(long count, long current) {
super.onLoading(count, current);
System.out.println(current+"/"+count);
textHttpView.setText(current+"/"+count);
}
@Override
public void onStart() {
System.out.println("onStart");
super.onStart();
}
@Override
public void onSuccess(Object t) {
super.onSuccess(t);
Toast.makeText(FinalActivityTest.this, "onSuccess: "+t.toString(), Toast.LENGTH_SHORT).show();
textHttpView.setText(t.toString().length());
}
});
}