80,348
社区成员
发帖
与我相关
我的任务
分享
private class LoginThread extends Thread {
@Override
public void run() {
Looper.prepare();
String httpUrl = "http://192.168.1.102:8080/StudyCase1/user/login_android";
HttpPost httpRequest = new HttpPost(httpUrl);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", str_loginName));
params.add(new BasicNameValuePair("password", str_loginPassword));
try {
httpRequest.setEntity(new UrlEncodedFormEntity(params,
HTTP.UTF_8));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
HttpClient httpclient = new DefaultHttpClient();
Log.e("aaa1", httpRequest + "");
Log.e("aaa2", httpclient + "");
HttpResponse httpResponse = null;
try {
httpResponse = httpclient.execute(httpRequest);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
Log.e("aaa3", httpResponse + "");
if (httpResponse.getStatusLine().getStatusCode() ==
HttpStatus.SC_OK) {
String strResult = null;
try {
strResult = EntityUtils.toString(httpResponse.getEntity());
} catch (IOException e) {
e.printStackTrace();
}
if (strResult.indexOf("success") != -1) {
Toast.makeText(Login.this, "登陆成功",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Login.this, "登陆失败",
Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(Login.this, "请求错误", Toast.LENGTH_SHORT).show();
}