Cannot login to website with Android application

285 Views Asked by At

I am trying to connect to my University's website using an Android app I am writing in Eclipse (Android v. 4.3), provide my credentials, and then stay logged in to download my class schedule. I have searched these forums for days and tried many different methods.

I am easily able to do this task using HtmlUnit in Java. I can access the website, log on, and go to the page with the data I need. However, HtmlUnit does not play well with Android apps, as it uses many external libraries with dependencies that cause the dreaded dalvikvm 1 error.

I have tried to make the connection with Jsoup, HttpsURLConnection, and HtmlClient. All the methods I try have the same result, i.e., I can "get" the website data, but I cannot "post" to it. I have tried setting the cookies up, the code is in an AsyncTask, and I have made sure my manifest internet permission is set.

Here is some sample code I have tried:

HtmlClient attempt:

public class MIXConnect extends AsyncTask<String, Void, String>
    {
        protected String doInBackground(String... loginInfo)
        {
            String result = "";
        try
        {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(
                    "https://star.wvu.edu/pls/starprod/twbkwbis.P_WWWLogin");
            httpPost.addHeader("User-Agent",
                    "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
            nameValuePairs.add(new BasicNameValuePair("sid", loginInfo[0]));
            nameValuePairs.add(new BasicNameValuePair("PIN", loginInfo[1]));
            nameValuePairs
                    .add(new BasicNameValuePair("ButtonSelected", "Login"));

            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpClient.execute(httpPost);
            Log.d("SPeKAM", "response stat code "
                    + response.getStatusLine().getStatusCode());

            if (response.getStatusLine().getStatusCode() < 400)
            {

                String cookie = response.getFirstHeader("Set-Cookie")
                        .getValue();
                Log.d("SPeKAM", "cookie: " + cookie);

                // get the contacts page
                HttpGet getSchedule = new HttpGet(
                        "https://star.wvu.edu/pls/starprod/bwskcrse.P_CrseSchdDetl");
                getSchedule.setHeader("Cookie", cookie);
                response = httpClient.execute(getSchedule);

                InputStream ins = response.getEntity().getContent();
                BufferedReader in = new BufferedReader(new InputStreamReader(
                        ins));

                String inputLine;
                while ((inputLine = in.readLine()) != null)
                {
                    Log.d("SPeKAM", " " + inputLine);
                }

                in.close();
            } else
            {
                Log.d("SPeKAM", "Response error: "
                        + response.getStatusLine().getStatusCode());
            }
            return result;

        } catch (ClientProtocolException e)
        {
            Log.d("SPeKAM", "ClientProtocol Error: " + e.getMessage());
            e.printStackTrace();
        } catch (UnsupportedEncodingException e)
        {
            Log.d("SPeKAM", "UnsupportedEncoding Error: " + e.getMessage());
            e.printStackTrace();
        } catch (IOException e)
        {
            Log.d("SPeKAM", "IO Error: " + e.getMessage());
            e.printStackTrace();
        }
        return result;
    }
}

Log.d output:

12-04 09:08:36.987: D/SPeKAM(875): response stat code 404
12-04 09:08:36.987: D/SPeKAM(875): Response error: 404

Jsoup attempt:

public class MIXConnect extends AsyncTask<String, Void, String>
    {
        protected String doInBackground(String... loginInfo)
        {
        String result = "";
        try
        {
            setTrustAllCerts();

            Document doc = Jsoup
                    .connect(
                            "https://star.wvu.edu/pls/starprod/twbkwbis.P_WWWLogin")
                    .followRedirects(true)
                    .header("User-Agent",
                            "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)")
                    .data("sid", loginInfo[0]).data("PIN", loginInfo[1])
                    .data("ButtonSelected", "Login").post();
            Log.d("SPeKAM", doc.html());
            return result;

        } catch (ClientProtocolException e)
        {
            Log.d("SPeKAM", "ClientProtocol Error: " + e.getMessage());
            e.printStackTrace();
        } catch (UnsupportedEncodingException e)
        {
            Log.d("SPeKAM", "UnsupportedEncoding Error: " + e.getMessage());
            e.printStackTrace();
        } catch (IOException e)
        {
            Log.d("SPeKAM", "IO Error: " + e.getMessage());
            e.printStackTrace();
        } catch (Exception e)
        {
            Log.d("SPeKAM", "Error: " + e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    private void setTrustAllCerts() throws Exception
    {
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager()
        {
            public java.security.cert.X509Certificate[] getAcceptedIssuers()
            {
                return null;
            }

            public void checkClientTrusted(
                    java.security.cert.X509Certificate[] certs, String authType)
            {
            }

            public void checkServerTrusted(
                    java.security.cert.X509Certificate[] certs, String authType)
            {
            }
        } };

        // Install the all-trusting trust manager
        try
        {
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, trustAllCerts, new java.security.SecureRandom());
            HttpsURLConnection
                    .setDefaultSSLSocketFactory(sc.getSocketFactory());
            HttpsURLConnection
                    .setDefaultHostnameVerifier(new HostnameVerifier()
                    {
                        public boolean verify(String urlHostName,
                                SSLSession session)
                        {
                            return true;
                        }
                    });
        } catch (Exception e)
        {
            // We can not recover from this exception.
            e.printStackTrace();
        }
    }
}

Log.d output:

12-04 09:12:21.007: D/SPeKAM(938): IO Error: HTTP error fetching URL

System.err output:

12-04 09:12:21.027: W/System.err(938): org.jsoup.HttpStatusException: HTTP error fetching URL. Status=404, URL=https://star.wvu.edu/pls/starprod/twbkwbis.P_WWWLogin
12-04 09:12:21.027: W/System.err(938):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449)
12-04 09:12:21.027: W/System.err(938):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424)
12-04 09:12:21.037: W/System.err(938):  at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:178)
12-04 09:12:21.047: W/System.err(938):  at org.jsoup.helper.HttpConnection.post(HttpConnection.java:173)
12-04 09:12:21.047: W/System.err(938):  at edu.wvu.spekam.MIXConnect.doInBackground(MIXConnect.java:36)
12-04 09:12:21.047: W/System.err(938):  at edu.wvu.spekam.MIXConnect.doInBackground(MIXConnect.java:1)
12-04 09:12:21.047: W/System.err(938):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-04 09:12:21.047: W/System.err(938):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-04 09:12:21.047: W/System.err(938):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-04 09:12:21.057: W/System.err(938):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-04 09:12:21.067: W/System.err(938):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-04 09:12:21.067: W/System.err(938):  at java.lang.Thread.run(Thread.java:841)

HttpsURLConnection attempt:

public class MIXConnect extends AsyncTask<String, Void, String>
    {
        protected String doInBackground(String... loginInfo)
    {
        try
        {
            HttpsURLConnection urlc = null;
            DataOutputStream dataout = null;
            BufferedReader in = null;

            URL urlPreLog = new URL("https://star.wvu.edu");
            HttpsURLConnection.setFollowRedirects(false);
            urlc = (HttpsURLConnection) urlPreLog.openConnection();
            urlc.setDoOutput(false);
            urlc.setRequestMethod("GET");
            Log.d("SPeKAM", "response code: " + urlc.getResponseCode());
            Map<String, List<String>> map = urlc.getHeaderFields();
            String newCookie = "";
            if (map != null)
            {
                Log.d("SPeKAM", "Retrieving the map");
                List<String> list = map.get("Set-Cookie");
                if ((list != null) && (list.size() > 0))
                {
                    Log.d("SPeKAM", "retrieving the list");
                    newCookie = list.get(0)
                            .substring(0, list.get(0).indexOf("path")).trim();
                }
            }
            Log.d("SPeKAM", "Cookie: " + newCookie);
            urlc.disconnect();

            URL urlLog = new URL(
                    "https://star.wvu.edu/pls/starprod/twbkwbis.P_WWWLogin");
            HttpsURLConnection.setFollowRedirects(true);
            urlc = (HttpsURLConnection) urlLog.openConnection();
            urlc.setRequestMethod("POST");
            urlc.setDoOutput(true);
            urlc.setDoInput(true);
            urlc.setUseCaches(false);
            urlc.setAllowUserInteraction(false);
            urlc.setRequestProperty("Content-Type",
                    "application/x-www-form-urlencoded");
            urlc.setRequestProperty("Connection", "Keep-Alive");
            urlc.setRequestProperty("Accept", "*/*");
            urlc.setRequestProperty("Cookie", newCookie);
            urlc.setRequestProperty("User-Agent",
                    "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
            String output = "sid="
                    + URLEncoder.encode(loginInfo[0], HTTP.UTF_8) + "&PIN="
                    + URLEncoder.encode(loginInfo[1], HTTP.UTF_8)
                    + "&ButtonSelected="
                    + URLEncoder.encode("Login", HTTP.UTF_8);
            dataout = new DataOutputStream(urlc.getOutputStream());
            dataout.writeBytes(output);
            Log.d("SPeKAM", "Response code: " + urlc.getResponseCode());
            urlc.disconnect();

            URL urlSche = new URL(
                    "https://star.wvu.edu/pls/starprod/bwskcrse.P_CrseSchdDetl");
            urlc = (HttpsURLConnection) urlSche.openConnection();
            urlc.setRequestMethod("GET");
            urlc.setDoInput(true);
            urlc.setUseCaches(false);
            urlc.setAllowUserInteraction(false);
            urlc.setRequestProperty("Cookie", newCookie);
            urlc.setRequestProperty("User-Agent",
                    "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
            in = new BufferedReader(new InputStreamReader(
                    urlc.getInputStream(), Charset.forName("ISO-8859-15")),
                    8096);
            Log.d("SPeKAM", "Response code: " + urlc.getResponseCode());
            String response;
            StringBuilder sb = new StringBuilder();
            while ((response = in.readLine()) != null)
            {
                sb.append(response + "\n");
                Log.d("SPeKAM", response);
            }
            String result = sb.toString();
            urlc.disconnect();
            in.close();
            return result;

        } catch (ClientProtocolException e)
        {
            Log.d("SPeKAM", "ClientProtocol Error: " + e.getMessage());
            e.printStackTrace();
        } catch (UnsupportedEncodingException e)
        {
            Log.d("SPeKAM", "UnsupportedEncoding Error: " + e.getMessage());
            e.printStackTrace();
        } catch (IOException e)
        {
            Log.d("SPeKAM", "IO Error: " + e.getMessage());
            e.printStackTrace();
        }
        return null;
    }
}

Log.d output:

12-04 09:01:06.437: D/SPeKAM(809): response code: 200
12-04 09:01:06.457: D/SPeKAM(809): Retrieving the map
12-04 09:01:06.457: D/SPeKAM(809): retrieving the list
12-04 09:01:06.457: D/SPeKAM(809): Cookie: BIGipServerstarwls_7701=3251287709.5406.0000;
12-04 09:01:06.787: D/SPeKAM(809): Response code: 404
12-04 09:01:07.247: D/SPeKAM(809): Response code: 200
12-04 09:01:07.267: D/SPeKAM(809): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/transitional.dtd">
12-04 09:01:07.267: D/SPeKAM(809): <HTML lang="en">
12-04 09:01:07.267: D/SPeKAM(809): <HEAD>
12-04 09:01:07.267: D/SPeKAM(809): <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
12-04 09:01:07.267: D/SPeKAM(809): <META HTTP-EQUIV="Pragma" NAME="Cache-Control" CONTENT="no-cache">
12-04 09:01:07.267: D/SPeKAM(809): <META HTTP-EQUIV="Cache-Control" NAME="Cache-Control" CONTENT="no-cache">
12-04 09:01:07.267: D/SPeKAM(809): <LINK REL="stylesheet" HREF="/css/web_defaulthome.css" TYPE="text/css">
12-04 09:01:07.267: D/SPeKAM(809): <LINK REL="stylesheet" HREF="/css/web_defaultprint.css" TYPE="text/css" media="print">
12-04 09:01:07.267: D/SPeKAM(809): <TITLE>User Login</TITLE>
12-04 09:01:07.280: D/SPeKAM(809): <META HTTP-EQUIV="Content-Script-Type" NAME="Default_Script_Language" CONTENT="text/javascript">
12-04 09:01:07.280: D/SPeKAM(809): <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
12-04 09:01:07.280: D/SPeKAM(809): <!-- Hide JavaScript from older browsers 
12-04 09:01:07.280: D/SPeKAM(809): var submitcount=0;
12-04 09:01:07.280: D/SPeKAM(809): function checkSubmit() {
12-04 09:01:07.280: D/SPeKAM(809): if (submitcount == 0)
12-04 09:01:07.287: D/SPeKAM(809):    {
12-04 09:01:07.287: D/SPeKAM(809):    submitcount++;
12-04 09:01:07.287: D/SPeKAM(809):    return true;
12-04 09:01:07.287: D/SPeKAM(809):    }
12-04 09:01:07.287: D/SPeKAM(809): else
12-04 09:01:07.287: D/SPeKAM(809):    {
12-04 09:01:07.287: D/SPeKAM(809): alert("Your changes have already been submitted.");
12-04 09:01:07.287: D/SPeKAM(809):    return false;
12-04 09:01:07.287: D/SPeKAM(809):    }
12-04 09:01:07.299: D/SPeKAM(809): }
12-04 09:01:07.299: D/SPeKAM(809): //  End script hiding -->
12-04 09:01:07.299: D/SPeKAM(809): </SCRIPT>
12-04 09:01:07.299: D/SPeKAM(809): <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
12-04 09:01:07.299: D/SPeKAM(809): <!-- Hide JavaScript from older browsers 
12-04 09:01:07.299: D/SPeKAM(809): //  Function to open a window
12-04 09:01:07.299: D/SPeKAM(809): function windowOpen(window_url) {
12-04 09:01:07.299: D/SPeKAM(809):    helpWin = window.open(window_url,'','toolbar=yes,status=no,scrollbars=yes,menubar=yes,resizable=yes,directories=no,location=no,width=350,height=400');
12-04 09:01:07.299: D/SPeKAM(809):    if (document.images) { 
12-04 09:01:07.307: D/SPeKAM(809):        if (helpWin) helpWin.focus()
12-04 09:01:07.307: D/SPeKAM(809):    }
12-04 09:01:07.307: D/SPeKAM(809): }
12-04 09:01:07.307: D/SPeKAM(809): //  End script hiding -->
12-04 09:01:07.307: D/SPeKAM(809): </SCRIPT>
12-04 09:01:07.307: D/SPeKAM(809): </HEAD>
12-04 09:01:07.307: D/SPeKAM(809): <BODY  onload = "document.loginform.UserID.focus()" >
12-04 09:01:07.307: D/SPeKAM(809): <DIV class="headerwrapperdiv">
12-04 09:01:07.307: D/SPeKAM(809): <DIV class="pageheaderdiv1">
12-04 09:01:07.307: D/SPeKAM(809): <A HREF="#main_content" onMouseover="window.status='Go to Main Content'; return true" onMouseout="window.status=''; return true" OnFocus="window.status='Go to Main Content'; return true" onBlur="window.status=''; return true" class="skiplinks">Go to Main Content</A>
12-04 09:01:07.307: D/SPeKAM(809): </DIV>
12-04 09:01:07.318: D/SPeKAM(809): <TABLE  CLASS="plaintable" SUMMARY="This table displays Menu Items and Banner Search textbox."
12-04 09:01:07.318: D/SPeKAM(809):          WIDTH="100%">
12-04 09:01:07.318: D/SPeKAM(809): <TR>
12-04 09:01:07.318: D/SPeKAM(809): <TD CLASS="pldefault">
12-04 09:01:07.318: D/SPeKAM(809): <DIV class="headerlinksdiv2">
12-04 09:01:07.318: D/SPeKAM(809): &nbsp;
12-04 09:01:07.318: D/SPeKAM(809): </div>
12-04 09:01:07.318: D/SPeKAM(809): </TD>
12-04 09:01:07.318: D/SPeKAM(809): <TD CLASS="pldefault"><p class="rightaligntext">
12-04 09:01:07.318: D/SPeKAM(809): <SPAN class="pageheaderlinks">
12-04 09:01:07.327: D/SPeKAM(809): <A HREF="/wtlhelp/twbhhelp.htm" accesskey="H" onClick="popup = window.open('/wtlhelp/twbhhelp.htm', 'PopupPage','height=500,width=450,scrollbars=yes,resizable=yes'); return false" target="_blank" onMouseOver="window.status='';  return true" onMouseOut="window.status=''; return true"onFocus="window.status='';  return true" onBlur="window.status=''; return true"  class="submenulinktext2">HELP</A>
12-04 09:01:07.327: D/SPeKAM(809): |
12-04 09:01:07.327: D/SPeKAM(809): <A HREF="twbkwbis.P_Logout" accesskey="3" class="submenulinktext2">EXIT</A>
12-04 09:01:07.327: D/SPeKAM(809): </span>
12-04 09:01:07.327: D/SPeKAM(809): </TD>
12-04 09:01:07.337: D/SPeKAM(809): </TR>
12-04 09:01:07.337: D/SPeKAM(809): </TABLE>
12-04 09:01:07.337: D/SPeKAM(809): </DIV>
12-04 09:01:07.337: D/SPeKAM(809): <DIV class="pagetitlediv">
12-04 09:01:07.337: D/SPeKAM(809): <TABLE  CLASS="plaintable" SUMMARY="This table displays title and static header displays."
12-04 09:01:07.337: D/SPeKAM(809):    WIDTH="100%">
12-04 09:01:07.337: D/SPeKAM(809): <TR>
12-04 09:01:07.347: D/SPeKAM(809): <TD CLASS="pldefault">
12-04 09:01:07.347: D/SPeKAM(809): <H2>User Login</H2>
12-04 09:01:07.357: D/SPeKAM(809): </TD>
12-04 09:01:07.357: D/SPeKAM(809): <TD CLASS="pldefault">
12-04 09:01:07.357: D/SPeKAM(809): &nbsp;
12-04 09:01:07.357: D/SPeKAM(809): </TD>
12-04 09:01:07.357: D/SPeKAM(809): <TD CLASS="pldefault"><p class="rightaligntext">
12-04 09:01:07.357: D/SPeKAM(809): <DIV class="staticheaders">
12-04 09:01:07.357: D/SPeKAM(809): </div>
12-04 09:01:07.357: D/SPeKAM(809): </TD>
12-04 09:01:07.357: D/SPeKAM(809): </TR>
12-04 09:01:07.367: D/SPeKAM(809): <TR>
12-04 09:01:07.367: D/SPeKAM(809): <TD class="bg3" width="100%" colSpan=3><IMG SRC="/wtlgifs/web_transparent.gif" ALT="Transparent Image" CLASS="headerImg" TITLE="Transparent Image"  NAME="web_transparent" HSPACE=0 VSPACE=0 BORDER=0 HEIGHT=3 WIDTH=10></TD>
12-04 09:01:07.377: D/SPeKAM(809): </TR>
12-04 09:01:07.377: D/SPeKAM(809): </TABLE>
12-04 09:01:07.377: D/SPeKAM(809): <a name="main_content"></a>
12-04 09:01:07.377: D/SPeKAM(809): </DIV>
12-04 09:01:07.377: D/SPeKAM(809): <DIV class="pagebodydiv">
12-04 09:01:07.377: D/SPeKAM(809): <!--  ** END OF twbkwbis.P_OpenDoc **  -->
12-04 09:01:07.387: D/SPeKAM(809): <DIV class="infotextdiv"><TABLE  CLASS="infotexttable" SUMMARY="This layout table contains information that may be helpful in understanding the content and functionality of this page.  It could be a brief set of instructions, a description of error messages, or other special information."><TR><TD CLASS="indefault"><SPAN class="infotext"> <br><br><br><b><font color = black>TERMS OF USAGE:</font></b><br><FONT COLOR=#1E2B83>This system is for the use of authorized persons only.  Individuals using the computer system inappropriately, illegally, without authority, or in excess of their authority, will have their access to this system terminated.<br><br> <FONT COLOR=#1E2B83>Although WVU, PSC, and WVU Tech do not monitor the content of your activities on this system, by using this system, you expressly agree to permit the monitoring and release of any of your activities on this system to federal, state, and local authorities when such activities reveal evidence of possible criminal activity.  <p> <b><font color = black>1ST TIME LOGIN for newly admitted students:</font></b><br><FONT COLOR=#1E2B83>
12-04 09:01:07.387: D/SPeKAM(809): Your PIN/Password will be expired upon your first login to STAR and every 90 days thereafter. The default STAR PIN/Password is a six digit number comprised of your two digits Day of Birth plus the last four digits of your WVU ID. <i>For example: if you were born on March 7, and your WVU ID is 123-45-6789, then your STAR PIN/Password would be 076789. Your User ID can be either your numeric WVU ID or your MIX ID/MyID. </i>
12-04 09:01:07.387: D/SPeKAM(809): <p>Criteria for STAR PIN/Password: <p><ul>
12-04 09:01:07.397: D/SPeKAM(809): <li>Must be at least 6 characters long 
12-04 09:01:07.397: D/SPeKAM(809): <li>Is case sensitive 
12-04 09:01:07.397: D/SPeKAM(809): <li>May contain alphabetic, numeric, and/or the following special characters: <br>
12-04 09:01:07.397: D/SPeKAM(809): % + / ! ^ ? : . { } [ ] ~ - _ </SPAN></TD></TR></TABLE><P></DIV>
12-04 09:01:07.397: D/SPeKAM(809): <FORM ACTION="/pls/starprod/twbkwbis.P_ValLogin" METHOD="POST" NAME="loginform" AUTOCOMPLETE="OFF">
12-04 09:01:07.397: D/SPeKAM(809): <TABLE  CLASS="dataentrytable" SUMMARY="This data entry table is used to format the user login fields">
12-04 09:01:07.397: D/SPeKAM(809): <TR>
12-04 09:01:07.407: D/SPeKAM(809): <TD CLASS="delabel" scope="row" ><LABEL for=UserID><SPAN class="fieldlabeltext">User ID:</SPAN></LABEL></TD>
12-04 09:01:07.417: D/SPeKAM(809): <TD CLASS="dedefault"><INPUT TYPE="text" NAME="sid" SIZE="32" MAXLENGTH="30" ID="UserID" ></TD>
12-04 09:01:07.417: D/SPeKAM(809): </TR>
12-04 09:01:07.417: D/SPeKAM(809): <TR>
12-04 09:01:07.427: D/SPeKAM(809): <TD CLASS="delabel" scope="row" ><LABEL for=PIN><SPAN class="fieldlabeltext">PIN:</SPAN></LABEL></TD>
12-04 09:01:07.427: D/SPeKAM(809): <TD CLASS="dedefault"ID="PIN" ><INPUT TYPE="password" NAME="PIN" SIZE="21" MAXLENGTH="20"></TD>
12-04 09:01:07.427: D/SPeKAM(809): </TR>
12-04 09:01:07.437: D/SPeKAM(809): </TABLE>
12-04 09:01:07.437: D/SPeKAM(809): <P>
12-04 09:01:07.437: D/SPeKAM(809): <INPUT TYPE="submit" VALUE="Login">
12-04 09:01:07.437: D/SPeKAM(809): &nbsp;
12-04 09:01:07.447: D/SPeKAM(809): <INPUT TYPE="submit" NAME="ButtonSelected" VALUE="Forgot PIN/Password?">
12-04 09:01:07.457: D/SPeKAM(809): </FORM>
12-04 09:01:07.457: D/SPeKAM(809): <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" LANGUAGE="JScript">
12-04 09:01:07.457: D/SPeKAM(809): document.loginform.reset();
12-04 09:01:07.457: D/SPeKAM(809): //  End script hiding -->
12-04 09:01:07.457: D/SPeKAM(809): </SCRIPT>
12-04 09:01:07.457: D/SPeKAM(809): <!--  ** START OF twbkwbis.P_CloseDoc **  -->
12-04 09:01:07.469: D/SPeKAM(809): <TABLE  CLASS="plaintable" SUMMARY="This is table displays line separator at end of the page."
12-04 09:01:07.469: D/SPeKAM(809):                                              WIDTH="100%" cellSpacing=0 cellPadding=0 border=0><TR><TD class="bgtabon" width="100%" colSpan=2><IMG SRC="/wtlgifs/web_transparent.gif" ALT="Transparent Image" CLASS="headerImg" TITLE="Transparent Image"  NAME="web_transparent" HSPACE=0 VSPACE=0 BORDER=0 HEIGHT=3 WIDTH=10></TD></TR></TABLE>
12-04 09:01:07.469: D/SPeKAM(809): <A HREF="#top" onMouseover="window.status='Skip to top of page'; return true" onMouseout="window.status=''; return true" OnFocus="window.status='Skip to top of page'; return true" onBlur="window.status=''; return true" class="skiplinks">Skip to top of page</A>
12-04 09:01:07.469: D/SPeKAM(809): </DIV>
12-04 09:01:07.469: D/SPeKAM(809): <DIV class="footerbeforediv">
12-04 09:01:07.489: D/SPeKAM(809): </DIV>
12-04 09:01:07.489: D/SPeKAM(809): <DIV class="footerafterdiv">
12-04 09:01:07.489: D/SPeKAM(809): </DIV>
12-04 09:01:07.497: D/SPeKAM(809): <DIV class="globalafterdiv">
12-04 09:01:07.508: D/SPeKAM(809): </DIV>
12-04 09:01:07.508: D/SPeKAM(809): <DIV class="globalfooterdiv">
12-04 09:01:07.508: D/SPeKAM(809): </DIV>
12-04 09:01:07.508: D/SPeKAM(809): <DIV class="pagefooterdiv">
12-04 09:01:07.517: D/SPeKAM(809): <SPAN class="releasetext">Release: 8.5</SPAN>
12-04 09:01:07.517: D/SPeKAM(809): </DIV>
12-04 09:01:07.517: D/SPeKAM(809): <DIV class="poweredbydiv">
12-04 09:01:07.517: D/SPeKAM(809): </DIV>
12-04 09:01:07.517: D/SPeKAM(809): <DIV class="div1"></DIV>
12-04 09:01:07.517: D/SPeKAM(809): <DIV class="div2"></DIV>
12-04 09:01:07.517: D/SPeKAM(809): <DIV class="div3"></DIV>
12-04 09:01:07.527: D/SPeKAM(809): <DIV class="div4"></DIV>
12-04 09:01:07.527: D/SPeKAM(809): <DIV class="div5"></DIV>
12-04 09:01:07.527: D/SPeKAM(809): <DIV class="div6"></DIV>
12-04 09:01:07.527: D/SPeKAM(809): </BODY>
12-04 09:01:07.527: D/SPeKAM(809): </HTML>

On this one the html displayed is what you get if you try to access "https://star.wvu.edu/pls/starprod/bwskcrse.P_CrseSchdDetl" without being logged in, i.e., a login prompt.

ALL attempts have the same result, I can "get" the website I want, namely https://star.wvu.edu/pls/starprod/twbkwbis.P_WWWLogin, and view the HTML for it, but I cannot "post" any login info to it because it returns a 404 File Not Found error.

I am new to Android and http connections and am at my wits end, can anyone help?

EDIT:

Here is the working code using HtmlUnit, outside of Android:

public class TestMain
{

/**
 * @param args
 */
public static void main(String[] args)
{
    try
    {
        String mixID = validLoginID;
        String mixPIN = validPassword;

        final WebClient ie10 = new WebClient(
                BrowserVersion.INTERNET_EXPLORER_10);
        final HtmlPage star = ie10
                .getPage("https://star.wvu.edu/pls/starprod/twbkwbis.P_WWWLogin");
        final HtmlForm form = star.getFormByName("loginform");
        form.getInputByName("sid").setValueAttribute(mixID);
        form.getInputByName("PIN").setValueAttribute(mixPIN);
        form.getInputByValue("Login").click();
        final HtmlPage scheduleSelect = ie10
                .getPage("https://star.wvu.edu/pls/starprod/bwskcrse.P_CrseSchdDetl");
        final HtmlForm schedForm = scheduleSelect.getForms().get(1);
        schedForm.getSelectByName("term_in").setSelectedAttribute("201308",
                true);
        final HtmlPage schedule = schedForm.getInputByValue("Submit")
                .click();
        System.out.println(schedule.asText());

        String[] lines = schedule.asText().split("\n");
        for (String line : lines)
        {
            String[] possibleCourse = line.split("\t");
            if (possibleCourse.length == 12)
            {
                if (!possibleCourse[0].startsWith("CRN"))
                {
                    System.out.println(possibleCourse[0] + ","
                            + possibleCourse[1] + "," + possibleCourse[2]
                            + "," + possibleCourse[3] + ","
                            + possibleCourse[4] + "," + possibleCourse[5]
                            + "," + possibleCourse[8] + ","
                            + possibleCourse[9] + "," + possibleCourse[10]
                            + "," + possibleCourse[11]
                            + ",www.example1.com, www.example2.com");
                }
            }
        }
        ie10.closeAllWindows();
    } catch (ClientProtocolException e)
    {
        System.out.println("ClientProtocol Error: " + e.getMessage());
        e.printStackTrace();
    } catch (UnsupportedEncodingException e)
    {
        System.out.println("UnsupportedEncoding Error: " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e)
    {
        System.out.println("IO Error: " + e.getMessage());
        e.printStackTrace();
    }
}
}

And it's output:

Concise Student Schedule
Main Menu       Personal Information        Student Services & Housing      Financial Aid   
Go

RETURN TO MENU | | HELP | EXIT
Concise Student Schedule

valid identifier
 Fall 2013
 Dec 04, 2013 09:31 am
     This page lists the classes for which you are registered for the term. All of the detail information about the class is included.
NOTE: Courses dropped with a "W" will appear on this screen.
Name:   valid                                           Address:    valid
Classification: Graduate                                                valid
valid
Level:  Graduate                                                 
College:    Engineering Mineral Resources                                                
Major:  Computer Science                                                 
    Engineering Mineral Resources                                                
CRN Course  Title   Campus  Credits Level   Start Date  End Date    Days    Time    Location    Instructor
86157   CS 572 001  Adv Artificl Intelligence Tech  WVU Campus Course    3.000  GR  Aug 19, 2013    Dec 18, 2013    W   5:00 pm - 7:20 pm   Engineering Sciences Building G84   Reddy
80644   CS 797 001  Research    WVU Campus Course    6.000  GR  Aug 19, 2013    Dec 18, 2013        TBA Engineering Sciences Building   Adjeroh
            Total Credits:   9.000


[ Student Detail Schedule ]
Release: 8.4
86157,CS 572 001,Adv Artificl Intelligence Tech,WVU Campus Course, 3.000,GR,W,5:00 pm - 7:20 pm,Engineering Sciences Building G84,Reddy
,www.example1.com, www.example2.com
80644,CS 797 001,Research,WVU Campus Course, 6.000,GR, ,TBA,Engineering Sciences Building ,Adjeroh
,www.example1.com, www.example2.com
0

There are 0 best solutions below