从HTTPResponse中提取HTML

时间:2011-12-09 22:50:52

标签: android http-post httpresponse

我很难找到解决这个问题的方法,所以我希望你能帮助我。我正在使用HTTPost登录网站。我可以成功登录,但仍然存在问题。登录时,它首先将我带到一个“中间人页面”,将我重定向到主页面,主页似乎使用Window.onLoad函数来重定向我。当我获得响应的HTML时,它将获取重定向页面的HTML。该网站使用会话来保持我的登录,而不是cookie。我只需要获取我重定向到的FINAL页面的HTML。这是我的代码。谢谢。

HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(
            "https://secure.groupfusion.net/processlogin.php");
    String HTML = "";
    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
        nameValuePairs
                .add(new BasicNameValuePair(
                        "referral_page",
                        "/modules/gradebook/ui/gradebook.phtml?type=student_view&amp;sessionid=16beb2d321c8c845b751022a196dbeb1"));
        nameValuePairs.add(new BasicNameValuePair("currDomain",
                "beardenhs.knoxschools.org"));
        nameValuePairs.add(new BasicNameValuePair("username", username
                .getText().toString()));
        nameValuePairs.add(new BasicNameValuePair("password", password
                .getText().toString()));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        String g = httppost.getURI().toString();

        HttpResponse response = httpclient.execute(httppost);

        HTML = EntityUtils.toString(response.getEntity());
        sting.setText(HTML);

0 个答案:

没有答案