//HttpUtils实例化对象
HttpUtils http = new HttpUtils();
/*
*发送请求send(HttpMethod method, String url, RequestCallBack<T> callBack)
* method请求方式
* url请求地址
*RequestCallBack <String>请求完后的回调监听String是请求完后你想让他返回什么类型的
*/
http.send(HttpRequest.HttpMethod.GET, urlPath,new RequestCallBack<String>() {
@Override
public void onLoading(long total, long current, boolean isUploading) {
}
@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
String s = responseInfo.result;
System.out.println(s);
}
@Override
public void onStart() {
}
@Override
public void onFailure(HttpException error, String msg) {
}
});
//-----------------eclipse---中-----这么用-----------------------
//创建一个请求方法
private void HttpUtilRequest() {
//创建HttpUtils
HttpUtils httpUtils=new HttpUtils();
//发送GET请求
httpUtils.send(HttpMethod.GET, urlPath, new RequestCallBack<String>() {
@Override//失败
public void onFailure(HttpException arg0, String arg1) {
// TODO Auto-generated method stub
}
@Override//成功
public void onSuccess(ResponseInfo<String> arg0) {
String str=arg0.result;
Log.i("-----++++++-----+++++", str);
Message message=new Message();
message.what=0;
message.obj=str;
handler.sendMessage(message);
}
});
}
浙公网安备 33010602011771号