Android模拟登录数据获取不了?无法传递?
小白在做一个模拟登录教务系统的app,可是在post上遇到了问题,理想是如果登录成功了就跳转到logi_success的页面,然后将获得的html源码直接贴上(之后json解析),如果失败的话就跳转到login_fault页面,点击“返回”按钮返回到登录页面
然后我现在遇到的问题是:不知道是数据传递的问题还是其他?我点击登录没有反应,logcat也米有错误提示,不知道是不是获取不了数据还是怎样,希望各位大神指点下小白,谢谢
下面贴代码:
MainActivity.java:
public class MainActivity extends Activity {
public static final int SHOW_RESPONSE=0;
private EditText user_id;
private EditText password;
private EditText validate;
private ImageView photo;
private CheckBox keep;
private Button next_botton;
private Button login_botton;
private Bitmap showVerifation;
private boolean flag;
// http://jwxt.jmpt.cn:8125/JspHelloWorld/authImg 另一个验证码地址
// http://jwxt.jmpt.cn:8125/JspHelloWorld/authImg?now=Wed%20Jun%2001%202016%2022:42:07%20GMT+0800%20(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4
// 另一个验证码地址
String VERIFATIONURL = "http://jwxt.jmpt.cn:8125/JspHelloWorld/authImg?now=Wed%20Jun%2001%202016%2022:42:07%20GMT+0800%20(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4";// 验证码地址
String LOGINURL = "http://jwxt.jmpt.cn:8125/JspHelloWorld/login.jsp";// 登录页面
String MAINBODYHTML = "";// 获得个人主界面的HTML
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
user_id = (EditText) findViewById(R.id.user_id);
password = (EditText) findViewById(R.id.password);
validate = (EditText) findViewById(R.id.validate);
login_botton = (Button) findViewById(R.id.login_botton);
next_botton = (Button) findViewById(R.id.next_botton);
keep = (CheckBox) findViewById(R.id.keep);
photo = (ImageView) findViewById(R.id.photo);
login_botton.setOnClickListener(onClickListener);// 将EditText里的信息提交按钮
next_botton.setOnClickListener(onClickListener);// 刷选验证码按钮
//initView();
}
View.OnClickListener onClickListener = new View.OnClickListener() {
private boolean flase;
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.login_botton:
if (equals()) {
String user_id1 = (String) user_id.getEditableText()
.toString();
String password1 = (String) password.getEditableText()
.toString();
String validate1 = (String) validate.getEditableText()
.toString();
DoLogin(user_id1, password1, validate1);
// Intent intent = new Intent(MainActivity.this,login_fault.class);
// startActivity(intent);
}
break;
case R.id.next_botton:
DoGetVerifation();
break;
}
}
private boolean equals() {
// TODO Auto-generated method stub
if (user_id.getEditableText().toString().equals("")) {
Toast.makeText(MainActivity.this, "用户名不能为空", Toast.LENGTH_SHORT)
.show();
flag = flase;
} else if (password.getEditableText().toString().equals("")) {
Toast.makeText(MainActivity.this, "密码不能为空", Toast.LENGTH_SHORT)
.show();
flag = flase;
} else if (validate.getEditableText().toString().equals("")) {
Toast.makeText(MainActivity.this, "验证码不能为空", Toast.LENGTH_SHORT)
.show();
flag = flase;
} else {
flag = true;
}
return flag;
}
private void DoLogin(final String user_id1, final String password1,
final String validate1) {
// TODO Auto-generated method stub
new Thread(new Runnable() {
@Override
public void run() {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse;
HttpPost httpRequest = new HttpPost(LOGINURL);
// 设置post参数
List params = new ArrayList();
params.add(new BasicNameValuePair("actionId", "login"));
params.add(new BasicNameValuePair("actionmi", "m10"));
params.add(new BasicNameValuePair("osname", "Win7,?豸:pc"));
params.add(new BasicNameValuePair("pageId", "000101"));
params.add(new BasicNameValuePair("Yhm", "ѧ ?ţ?"));
params.add(new BasicNameValuePair("radiobutton", "student"));
params.add(new BasicNameValuePair("password", password1));
params.add(new BasicNameValuePair("validate", validate1));
params.add(new BasicNameValuePair("username", user_id1));
httpRequest.setHeader("Cookie",
"JSESSIONID=44983DD250A48E966B95381E2C472C29");
httpRequest.setHeader("Host", "jwxt.jmpt.cn:8125");
httpRequest.setHeader("Referer",
"http://jwxt.jmpt.cn:8125/JspHelloWorld/login.jsp");
httpRequest
.setHeader(
"User-Agent",
"Mozilla/5.0 (MSIE 9.0; Windows NT 6.1; WOW64; Trident/7.0; BOIE9;ZHCN; rv:11.0) like Gecko");
try {
// 发出HTTP request
httpRequest.setEntity(new UrlEncodedFormEntity(params,
"GBK"));
// 取得HTTP response
httpResponse = httpClient.execute(httpRequest); // 执行
// 若状态码为200 ok
if (httpResponse.getStatusLine().getStatusCode() == 200) { // 返回值正常
HttpEntity entity=httpResponse.getEntity();
String response=EntityUtils.toString(entity,"GBK");
Message message=new Message();
message.what=SHOW_RESPONSE;
message.obj=response.toString();
Handler handler=new Handler(){
public void handleMessage (Message msg){
switch(msg.what){
case SHOW_RESPONSE:
String response=(String)msg.obj;
Intent intent = new Intent(MainActivity.this,login_success.class);
startActivity(intent);
}
}
};
handler.sendMessage(message);
} else {
//Toast.makeText(MainActivity.this,"dsadsa",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this,login_fault.class);
startActivity(intent);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
private void DoGetVerifation() {
// TODO Auto-generated method stub
final Handler handler = new Handler() {
@SuppressWarnings("deprecation")
public void handleMessage(android.os.Message msg) {
if (msg.arg1 == 1) {
Bitmap bitmap = (Bitmap) msg.obj;
Drawable pic = new BitmapDrawable(bitmap);
// loginpic.setImageBitmap(bitmap);
photo.setBackgroundDrawable(pic);
}
};
};
final String urlString = "http://jwxt.jmpt.cn:8125/JspHelloWorld/authImg?now=Wed%20Jun%2001%202016%2022:42:07%20GMT+0800%20(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4";
new Thread() {
public void run() {
Message message = handler.obtainMessage();
message.obj = HttpBitmap.getHttpBitmap(urlString);
message.arg1 = 1;
handler.sendMessage(message);
};
}.start();
}
};
}
点击登录按钮的话logcat只有这些信息
对了,cookie的值不变,我也不知道为什么,反正用httpwatch查看的都是这个值
相关阅读:
markdown使用咨询
bootstrap按钮式下拉菜单如何和按钮一样宽度?
https://baidu.com/?ref=muzli这种/?ref=muzli是怎么做的,有什么含义?
查看git push 默认的远程分支名用什么命令?
mvc中的模型的疑问
PHP 无法删除cookie
如何转码微信多媒体下载接口的音频文件?
请教如何获取fastcgi缓存的key
如何用js实现字典?
query each() 如何操作后添加的DOM元素?
手机QQ聊天窗口显示有红包,点开却是文字
ios sdk 上传到95%就停止了
C#如何修改已经在控制台输出的数据?
哪些开源软件提供热更新,请简要描述下其更新策略。有哪些方案是你认为好的更新策略(不局限于热更新)
各位大神mogenerator not found……何解?
Sublime text有没有会话管理的插件?
如何实现在页面上所有内容加载完之前一直显示loading...页面?
JS 追加 HTML 的问题
php在一个请求中,发送另一个请求
为什么Long.parseLong最多只能转换19位数字,Long最大不是64位么?