获取 HTTPResponse 实体

发布于 2024-12-02 03:24:58 字数 2055 浏览 5 评论 0原文

我试图在服务器上执行 get 方法后从响应中获取 html 代码,当我尝试解析实体时,我的代码就会停止。并且执行只是停止在“String loginResponseBody = EntityUtils.toString(response .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);

PS 实体不为空,同一部分代码在应用程序的其他部分工作

P.PS 这完全是我的错,开始不明白我自己的代码..我应该在服务器上执行 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();
                }

I am trying to fetch the html code from the response after executing get method on the server and my code just stops when i try to parse the entity. And the execution just stops on the line "String loginResponseBody = EntityUtils.toString(response
.getEntity());"

what does it mean and are there anyother methods of doing so?

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. entity is not null and the same portion of code works in other parts of app

P.P.S. that is my fault totally, start not to understand my own code.. I was supposed to get reply after I execute GET function on the server, because after post i was getting redirect all the time(by server). So the final version is like:

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();
                }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文