Android: http login not having desired effect
<p>I couldn't seem to get my log in page to work, it kept telling me my username/password were incorrect when I obviously know they are not. So I started debugging and popping in log.v's and I found something interesting. Look for the line that says "//&lt;--- THIS LINE!"</p>

<pre><code>class LogMeIn extends AsyncTask&lt;String, Void, String&gt; {
    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&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(
                    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); // &lt;--- 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;
}
</code></pre>

<p>Now I was expecting a response like "true" or "1". Based on that I would know the username/password was correct and I launch my main activity and life goes on. However what I got back was this </p>

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

<p>furthermore if I trim off the /login.php at the end of the URL to say "<a href="http://www.whatever.com" rel="nofollow">http://www.whatever.com</a>" I get a wall of similar html just much longer. </p>

<p>Needless to say I'm doing this wrong, and my login fails regardless of whether the username/password is correct. Where did I go wrong? I can't seem to figure it out.</p>
