获取 HTTPResponse 实体
我试图在服务器上执行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论