我正在尝试实现一个简单的 HTTP 请求。该请求将验证来自服务器的用户名和密码。服务器配置为只返回两个错误代码,200 表示已验证,404 表示其他所有错误代码。我已经用 eclipse 进行了广泛的调试,发现我总是收到代码 404。在发布之前我已经阅读了所有其他现有问题。
private class loginTask extends AsyncTask<String, Integer, Boolean> {
String check;
@Override
protected Boolean doInBackground(String... arg0) {
("http://www.unite.upmc.edu/account/IPhoneLogin?username=username&password=password
String username = arg0[0];
String password = arg0[1];
URI uri = null;
try {
uri = new URI("http://unite.upmc.edu/account/IPhoneLogin?"+"username="+username+"&"+"password="+password);// I know the method is called IPhoneLogin, it's being used by both Android and IOS clients
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
HttpClient client = new DefaultHttpClient();
try {//Look here
HttpResponse response = client.execute(new HttpGet(uri));
String code = "" + response.getStatusLine().getStatusCode();
check = code;
if(code.equals("200")){
loggedIn = true;
}else{
//need to re-enter username and password
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
hasPin = false;
return true;
}
@Override
protected void onProgressUpdate(Integer... integers) {
setProgress(integers[0]);
}
@Override
protected void onPreExecute() {
ProgressDialog dialog = new ProgressDialog(UniteActivity.this);
dialog.setMessage("Logging in...." + check);
dialog.show();
}
我知道服务器已经启动并且密码和用户名是正确的,因为我已经使用 Internet Explorer 正常登录了很多次。我正在使用带有 Android SDK 的 Eclipse IDE,我担心这可能是它提供的错误模拟器的产品。关于我做错了什么的任何想法?