获取HTTPResponse实体

时间:2011-08-29 04:20:12

标签: java html httpclient httpresponse

我试图在服务器上执行get方法后从响应中获取html代码,当我尝试解析实体时,我的代码就停止了。执行只是停在“String loginResponseBody = EntityUtils.toString(响应                             .getEntity());“

这是什么意思,还有其他方法吗?

HttpResponse response = client.httpPost1(viewState,
                            "http://syspower.skm.no/syspower3/mobile/Login.aspx",
                            username, password);
                    System.out.println("got response");
                    System.out.println(response);

                    System.out.println(response.getStatusLine());

                    String loginResponseBody = EntityUtils.toString(response
                            .getEntity());
                    System.out.println(loginResponseBody);

                    String table = clearHTML(loginResponseBody);


System.out.println(table);

P.S。实体不是null,并且代码的相同部分在app的其他部分中起作用

P.P.S。这完全是我的错,开始不了解我自己的代码..我应该在服务器上执行GET功能后获得回复,因为在帖子后我一直在重定向(由服务器)。所以最终版本就像:

String viewState = client
                        .httpGetViewstate("http://syspower.skm.no/syspower3/mobile/Login.aspx");

                HttpResponse response = client.httpPost1(viewState,
                        "http://syspower.skm.no/syspower3/mobile/Login.aspx",
                        userPrefs.getUserName(), userPrefs.getUserPassword());
                System.out.println("posted!");

                String commentsHtml = client
                        .httpGet("http://syspower.skm.no/syspower3/mobile/PriceTables.aspx");

                // System.out.println(commentsHtml);

                if (commentsHtml.contains("table")) { //or better to do with the Jsoup to search for first table
                    success = true;
                    System.out.println("username is ok");

                    System.out.println(commentsHtml);

                    this.finish();
                } else {
                    System.out.println("back again..");
                    fail = true;
                    loginBox();
                }

0 个答案:

没有答案