1、xutils3get
设置权限 在AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">
创建一个myApplication
public class MyApplication extends Application {
@Override public void onCreate() {
super.onCreate(); x.Ext.init(this);
}}
在 Activity上 注解
@ContentView(value = R.layout.activity_main)
public class MainActivity extends AppCompatActivity {
//找到
viewPage private ViewPager viewPager;
//fragment集合
private List fragmentList;
private RadioGroup radioGroup;
@ViewInject(value = R.id.login_item)
private Button item;
String url = "http://www.baidu.com";
RequestParams params = new RequestParams(url);// params.addQueryStringParameter("userTel","18137777189");// params.addQueryStringParameter("userPass","123456");
Callback.Cancelable cancelable = x.http().
get(params, new Callback.CommonCallback() {
@Override public void onSuccess(String result) {
Log.i("返回数据","登录"+result);
}
@Override public void onError(Throwable ex, boolean isOnCallback) {
}
@Override public void onCancelled(CancelledException cex) {
}
@Override public void onFinished() {
} });
cancelable.cancel();
2、post请求
String url = "http://www.baidu.com";
RequestParams params =newRequestParams(url);
params.addBodyParameter("userTel","18137777189");
params.addBodyParameter("userPass","123456");
x.http().post(params, new Callback.CommonCallback() {
@Override
publicvoid onSuccess(String result) {
Log.i("返回数据","登录"+result);
}
@Override
public void onError(Throwable ex, boolean isOnCallback) { }
@Override
public void onCancelled(CancelledException cex) { }
@Override
public void onFinished() { }
});
网友评论