x.Ext.init(getApplication()); editText1= (EditText) findViewById(R.id.username); editText2= (EditText) findViewById(R.id.password); button= (Button) findViewById(R.id.login_btn); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String account=editText1.getText().toString(); final String password=editText2.getText().toString(); JSONObject js_request = new JSONObject();//服务器需要传参的json对象 try { js_request.put("account", account);//添加相应键值对 js_request.put("password", password); } catch (JSONException e) { e.printStackTrace(); } RequestParams requestParams = new RequestParams(Contants.LOGIN_URL); //设置post提交数据格式为json requestParams.setAsJsonContent(true); requestParams.setBodyContent(js_request.toString()); x.http().post(requestParams, new Callback.CommonCallback<String>() { @Override public void onSuccess(String result) { System.out.println("**ok"+result);//code:1:表示成功,6:表示账号或密码不存在 try { //获取cookies值 DbCookieStore instance=DbCookieStore.INSTANCE; List<HttpCookie> cookies=instance.getCookies(); for(int i=0;i<cookies.size();i++){ values=String.valueOf(cookies.get(i)); } System.out.println("****"+values); JSONObject object=new JSONObject(result); String code=object.getString("code"); if(code.equals("1")){ Intent intent=new Intent(MainActivity.this,Owers_Activity.class); startActivity(intent); } else{ Toast.makeText(getApplicationContext(),"账号或密码错误!",Toast.LENGTH_SHORT).show(); } } catch (Exception e) { e.printStackTrace(); } } @Override public void onError(Throwable ex, boolean isOnCallback) { System.out.println("errot"); } @Override public void onCancelled(CancelledException cex) { } @Override public void onFinished() { } }); } }); }