0

我是 Web 开发领域的新手,我尝试将用户名和密码发送到 php 脚本,然后将结果返回为 0 或 1。但返回时我没有对它们进行编码。我的问题是 System.out.println(EntityUtils.toString(entity)) 在提供正确的用户名和密码时将返回值打印为 1,但我无法比较或将该值分配给变量。

        response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        System.out.println(EntityUtils.toString(entity));
        String s=EntityUtils.toString(entity);

但是当我尝试比较字符串值时,IDE 输出显示尝试从关闭的流中读取

4

2 回答 2

1

执行“System.out.println(EntityUtils.toString(entity));”时,http响应内容已被消耗 所以,当你再次调用“实体”时,你会得到错误。

基于流的http内容,您只能阅读一次。

以下代码可能有效:

response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
String s=EntityUtils.toString(entity);
System.out.println(s);
于 2013-07-17T05:44:04.527 回答
0

你是这个意思吗?:

"1".equals(s);
于 2013-07-17T05:36:12.143 回答