AsyncHttpClient使用示例代码
发布时间:2020-05-28 22:20:48 所属栏目:Java 来源:互联网
导读:AsyncHttpClient使用示例代码
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 实现http异步请求get,post请求,也可以用作文件上传。 下面是登录的示例 AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.add("RequestType","");
params.add("UserID","-1");
params.add("NurseID","-1");
params.add("HospitalId","-1");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("UserCode",username);
jsonObject.put("Password",password);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
params.add("RequestParam",jsonObject.toString());
client.get(path,params,new TextHttpResponseHandler() {
@Override
public void onSuccess(int statusCode,Header[] headers,String responseString) {
// TODO Auto-generated method stub
if (statusCode == 200) {
// Toast.makeText(getApplicationContext(),// responseString,Toast.LENGTH_SHORT)
// .show();
Intent intent = new Intent();
intent.setClass(
getApplicationContext(),MainActivity.class);
startActivity(intent);
} else {
Intent intent = new Intent();
intent.setClass(
getApplicationContext(),MainActivity.class);
startActivity(intent);
}
} else {
Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else {
Toast.makeText(getApplicationContext(),"网络连接超时",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(int statusCode,String responseString,Throwable throwable) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),responseString,Toast.LENGTH_SHORT).show();
}
1.声明一个client对象,初始化 以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
