1

我似乎无法让我的登录页面正常工作,它一直告诉我我的用户名/密码不正确,而我显然知道它们不正确。所以我开始调试并弹出 log.v,我发现了一些有趣的东西。查找显示“//<--- THIS LINE!”的行

class LogMeIn extends AsyncTask<String, Void, String> {
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://www.fakesite.com/login.php");

    protected String doInBackground(String... urls) {

        try {
            username = un.getText().toString();
            password = pw.getText().toString();
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
                    2);
            nameValuePairs
                    .add(new BasicNameValuePair("username", username));
            nameValuePairs
                    .add(new BasicNameValuePair("password", password));
            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            HttpResponse response = client.execute(post);
            String res = inputStream(response.getEntity().getContent())
                    .toString();
            Log.v("RESPONSE", res); // <--- THIS LINE!

            // if username and password are valid, launch main activity
            if (res.toString() == "1") {
                Intent logIn = new Intent(getApplicationContext(), Main.class);
                startActivity(logIn);                   
            } 
            // send the user a message saying the login failed
            else {
                runOnUiThread(new Runnable() {
                    public void run() {                         
                        pw.setText("");
                        fail.setText(R.string.fail);
                    }
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    protected void onPostExecute(String file_url) {

    }
}

private StringBuilder inputStream(InputStream input) {
    String line = "";
    StringBuilder total = new StringBuilder();
    BufferedReader read = new BufferedReader(new InputStreamReader(input));

    try {
        while ((line = read.readLine()) != null) {
            total.append(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return total;
}

现在我期待像“真”或“1”这样的回应。基于此,我会知道用户名/密码是正确的,然后我开始了我的主要活动,生活还在继续。然而我得到的是这个

05-18 15:41:27.620: V/RESPONSE(27641):  <!--<script>window.location.href="";</script>-->       <!-- <meta http-equiv="refresh" content="0;url=">                --> 

此外,如果我将 URL 末尾的 /login.php 修剪为“ http://www.whatever.com ”,我会得到更长的类似 html 墙。

不用说我做错了,无论用户名/密码是否正确,我的登录都会失败。我哪里做错了?我似乎无法弄清楚。

4

0 回答 0